Numbers whose count of divisors is prime: Difference between revisions
Content added Content deleted
(Realize in F#) |
(Added XPL0 example.) |
||
Line 870: | Line 870: | ||
Found 79 such integers (16 under 1,000). |
Found 79 such integers (16 under 1,000). |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<lang XPL0>func IsPrime(N); \Return 'true' if N is a prime number |
|||
int N, I; |
|||
[if N <= 1 then return false; |
|||
for I:= 2 to sqrt(N) do |
|||
if rem(N/I) = 0 then return false; |
|||
return true; |
|||
]; |
|||
func Divisors(N); \Return number of unique divisors of N |
|||
int N, SN, Count, D; |
|||
[SN:= sqrt(N); \N must be a perfect square to get an odd (prime>2) count |
|||
if SN*SN # N then return 0; |
|||
Count:= 3; \SN, 1 and N are unique divisors of N >= 4 |
|||
for D:= 2 to SN-1 do |
|||
if rem(N/D) = 0 then Count:= Count+2; |
|||
return Count; |
|||
]; |
|||
int N, Count; |
|||
[Count:= 0; |
|||
for N:= 4 to 100_000-1 do |
|||
if IsPrime(Divisors(N)) then |
|||
[Count:= Count+1; |
|||
IntOut(0, N); |
|||
if rem(Count/10) = 0 then CrLf(0) else ChOut(0, 9\tab\); |
|||
]; |
|||
]</lang> |
|||
{{out}} |
|||
<pre> |
|||
4 9 16 25 49 64 81 121 169 289 |
|||
361 529 625 729 841 961 1024 1369 1681 1849 |
|||
2209 2401 2809 3481 3721 4096 4489 5041 5329 6241 |
|||
6889 7921 9409 10201 10609 11449 11881 12769 14641 15625 |
|||
16129 17161 18769 19321 22201 22801 24649 26569 27889 28561 |
|||
29929 32041 32761 36481 37249 38809 39601 44521 49729 51529 |
|||
52441 54289 57121 58081 59049 63001 65536 66049 69169 72361 |
|||
73441 76729 78961 80089 83521 85849 94249 96721 97969 |
|||
</pre> |
</pre> |