Chowla numbers: Difference between revisions

(→‎{{header|Prolog}}: Adding Prolog)
(→‎{{header|Picat}}: Adding Picat)
Line 3,410:
become 4s and 90s respectively, without finding anything else. Obviously 1.4e11 and 2.4e18
were picked to minimise the run times.
 
=={{header|Picat}}==
{{trans|Prolog}}
{{works with|Picat}}
<lang Picat>
table
chowla(1) = 0.
chowla(2) = 0.
chowla(3) = 0.
chowla(N) = C, N>3 =>
Max = floor(sqrt(N)),
Sum = 0,
foreach (X in 2..Max, N mod X == 0)
Y := N div X,
Sum := Sum + X + Y
end,
if (N == Max * Max) then
Sum := Sum - Max
end,
C = Sum.
 
main =>
foreach (I in 1..37)
printf("chowla(%d) = %d\n", I, chowla(I))
end,
Ranges = {100, 1000, 10000, 100000, 1000000, 10000000},
foreach (Range in Ranges)
Count = 0,
foreach (I in 2..Range)
if (chowla(I) == 0) then
Count := Count + 1
end
end,
printf("There are %d primes less than %d.\n", Count, Range)
end,
Limit = 35000000,
Count = 0,
foreach (I in 2..Limit)
if (chowla(I) == I-1) then
printf("%d is a perfect number\n", I),
Count := Count + 1
end
end,
printf("There are %d perfect numbers less than %d.\n", Count, Limit).
</lang>
{{out}}
<pre>
chowla(1) = 0
chowla(2) = 0
chowla(3) = 0
chowla(4) = 2
chowla(5) = 0
chowla(6) = 5
chowla(7) = 0
chowla(8) = 6
chowla(9) = 3
chowla(10) = 7
chowla(11) = 0
chowla(12) = 15
chowla(13) = 0
chowla(14) = 9
chowla(15) = 8
chowla(16) = 14
chowla(17) = 0
chowla(18) = 20
chowla(19) = 0
chowla(20) = 21
chowla(21) = 10
chowla(22) = 13
chowla(23) = 0
chowla(24) = 35
chowla(25) = 5
chowla(26) = 15
chowla(27) = 12
chowla(28) = 27
chowla(29) = 0
chowla(30) = 41
chowla(31) = 0
chowla(32) = 30
chowla(33) = 14
chowla(34) = 19
chowla(35) = 12
chowla(36) = 54
chowla(37) = 0
There are 25 primes less than 100.
There are 168 primes less than 1000.
There are 1229 primes less than 10000.
There are 9592 primes less than 100000.
There are 78498 primes less than 1000000.
There are 664579 primes less than 10000000.
6 is a perfect number
28 is a perfect number
496 is a perfect number
8128 is a perfect number
33550336 is a perfect number
There are 5 perfect numbers less than 35000000.
</pre>
 
=={{header|PicoLisp}}==