Chowla numbers: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Changed to Wren S/H) |
(Add PARI/GP implementation) |
||
Line 3,258: | Line 3,258: | ||
There are 5 perfect numbers < 350,000,000 |
There are 5 perfect numbers < 350,000,000 |
||
</pre> |
</pre> |
||
=={{header|PARI/GP}}== |
|||
{{trans|Julia}} |
|||
<syntaxhighlight lang="PARI/GP"> |
|||
chowla(n) = { |
|||
if (n < 1, error("Chowla function argument must be positive")); |
|||
if (n < 4, return(0)); |
|||
my(divs = divisors(n)); |
|||
sum(i=1, #divs, divs[i]) - n - 1; |
|||
} |
|||
\\ Function to count Chowla numbers |
|||
countchowlas(n, asperfect = 1, verbose = 1) = { |
|||
my(count = 0, chow, i); |
|||
for (i = 2, n, |
|||
chow = chowla(i); |
|||
if ( (asperfect && (chow == i - 1)) || ((!asperfect) && (chow == 0)), |
|||
count++; |
|||
if (verbose, print("The number " i " is " if (asperfect, "perfect.", "prime."))); |
|||
); |
|||
); |
|||
count; |
|||
} |
|||
\\ Main execution block |
|||
{ |
|||
print("The first 37 chowla numbers are:"); |
|||
for (i = 1, 37, printf("Chowla(%s) is %s\n", Str(i), Str(chowla(i)) ) ); |
|||
m=100; |
|||
while(m<=10000000, print("The count of the primes up to " m " is " countchowlas(m, 0, 0)); m=m*10); |
|||
print("The count of perfect numbers up to 35,000,000 is " countchowlas(35000000, 1, 1)); |
|||
} |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
The first 37 chowla numbers are: |
|||
Chowla(1) is 0 |
|||
Chowla(2) is 0 |
|||
Chowla(3) is 0 |
|||
Chowla(4) is 2 |
|||
Chowla(5) is 0 |
|||
Chowla(6) is 5 |
|||
Chowla(7) is 0 |
|||
Chowla(8) is 6 |
|||
Chowla(9) is 3 |
|||
Chowla(10) is 7 |
|||
Chowla(11) is 0 |
|||
Chowla(12) is 15 |
|||
Chowla(13) is 0 |
|||
Chowla(14) is 9 |
|||
Chowla(15) is 8 |
|||
Chowla(16) is 14 |
|||
Chowla(17) is 0 |
|||
Chowla(18) is 20 |
|||
Chowla(19) is 0 |
|||
Chowla(20) is 21 |
|||
Chowla(21) is 10 |
|||
Chowla(22) is 13 |
|||
Chowla(23) is 0 |
|||
Chowla(24) is 35 |
|||
Chowla(25) is 5 |
|||
Chowla(26) is 15 |
|||
Chowla(27) is 12 |
|||
Chowla(28) is 27 |
|||
Chowla(29) is 0 |
|||
Chowla(30) is 41 |
|||
Chowla(31) is 0 |
|||
Chowla(32) is 30 |
|||
Chowla(33) is 14 |
|||
Chowla(34) is 19 |
|||
Chowla(35) is 12 |
|||
Chowla(36) is 54 |
|||
Chowla(37) is 0 |
|||
The count of the primes up to 100 is 25 |
|||
The count of the primes up to 1000 is 168 |
|||
The count of the primes up to 10000 is 1229 |
|||
The count of the primes up to 100000 is 9592 |
|||
The count of the primes up to 1000000 is 78498 |
|||
The count of the primes up to 10000000 is 664579 |
|||
The number 6 is perfect. |
|||
The number 28 is perfect. |
|||
The number 496 is perfect. |
|||
The number 8128 is perfect. |
|||
The number 33550336 is perfect. |
|||
The count of perfect numbers up to 35000000 is 5. |
|||
</pre> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
{{works with|Free Pascal}} |
{{works with|Free Pascal}} |