Chowla numbers: Difference between revisions
Content added Content deleted
(Added XPL0 example.) |
|||
Line 5,252: | Line 5,252: | ||
33,550,336 is a perfect number |
33,550,336 is a perfect number |
||
There are 5 perfect numbers <= 35,000,000 |
There are 5 perfect numbers <= 35,000,000 |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<lang XPL0>func Chowla(N); \Return sum of divisors |
|||
int N, Div, Sum, Quot; |
|||
[Div:= 2; Sum:= 0; |
|||
loop [Quot:= N/Div; |
|||
if Quot < Div then quit; |
|||
if Quot = Div and rem(0) = 0 then \N is a square |
|||
[Sum:= Sum+Quot; quit]; |
|||
if rem(0) = 0 then |
|||
Sum:= Sum + Div + Quot; |
|||
Div:= Div+1; |
|||
]; |
|||
return Sum; |
|||
]; |
|||
int N, C, P; |
|||
[for N:= 1 to 37 do |
|||
[IntOut(0, N); Text(0, ": "); |
|||
IntOut(0, Chowla(N)); CrLf(0); |
|||
]; |
|||
C:= 1; \count 2 as prime |
|||
N:= 3; \only check odd numbers |
|||
repeat if Chowla(N) = 0 then \N is prime |
|||
C:= C+1; |
|||
case N+1 of 100, 1000, 10_000, 100_000, 1_000_000, 10_000_000: |
|||
[Text(0, "There are "); IntOut(0, C); Text(0, " primes < "); |
|||
IntOut(0, N+1); CrLf(0)] |
|||
other []; |
|||
N:= N+2; |
|||
until N >= 10_000_000; |
|||
P:= 1; \perfect numbers are of form: 2^(P-1) * (2^P - 1) |
|||
loop [P:= P*2; |
|||
N:= P*(P*2-1); |
|||
if N > 35_000_000 then quit; |
|||
if Chowla(N) = N-1 then \N is perfect |
|||
[IntOut(0, N); CrLf(0)]; |
|||
]; |
|||
]</lang> |
|||
{{out}} |
|||
<pre> |
|||
1: 0 |
|||
2: 0 |
|||
3: 0 |
|||
4: 2 |
|||
5: 0 |
|||
6: 5 |
|||
7: 0 |
|||
8: 6 |
|||
9: 3 |
|||
10: 7 |
|||
11: 0 |
|||
12: 15 |
|||
13: 0 |
|||
14: 9 |
|||
15: 8 |
|||
16: 14 |
|||
17: 0 |
|||
18: 20 |
|||
19: 0 |
|||
20: 21 |
|||
21: 10 |
|||
22: 13 |
|||
23: 0 |
|||
24: 35 |
|||
25: 5 |
|||
26: 15 |
|||
27: 12 |
|||
28: 27 |
|||
29: 0 |
|||
30: 41 |
|||
31: 0 |
|||
32: 30 |
|||
33: 14 |
|||
34: 19 |
|||
35: 12 |
|||
36: 54 |
|||
37: 0 |
|||
There are 25 primes < 100 |
|||
There are 168 primes < 1000 |
|||
There are 1229 primes < 10000 |
|||
There are 9592 primes < 100000 |
|||
There are 78498 primes < 1000000 |
|||
There are 664579 primes < 10000000 |
|||
6 |
|||
28 |
|||
496 |
|||
8128 |
|||
33550336 |
|||
</pre> |
</pre> |
||