Chowla numbers: Difference between revisions

no edit summary
No edit summary
Line 1,532:
33,550,336 is a perfect number
There are 5 perfect mumbers up to 35,000,000
</pre>
 
=={{header|EMal}}==
{{trans|Go}}
<syntaxhighlight lang="emal">
fun chowla = int by int n
int sum = 0
int j = 0
for int i = 2; i * i <= n; i++ do
if n % i == 0 do sum += i + when(i == (j = n / i), 0, j) end
end
return sum
end
fun sieve = List by int limit
List c = logic[].with(limit)
for int i = 3; i * 3 < limit; i += 2
if c[i] or chowla(i) != 0 do continue end
for int j = 3 * i; j < limit; j += 2 * i do c[j] = true end
end
return c
end
# find and display (1 per line) for the 1st 37 integers
for int i = 1; i <= 37; i++ do writeLine("chowla(" + i + ") = " + chowla(i)) end
int count = 1
int limit = 10000000
int power = 100
List c = sieve(limit)
for int i = 3; i < limit; i += 2
if not c[i] do count++ end
if i == power - 1
writeLine("Count of primes up to " + power + " = " + count)
power *= 10
end
end
count = 0
limit = 35000000
int k = 2
int kk = 3
int p
for int i = 2; ; i++
if (p = k * kk) > limit do break end
if chowla(p) == p - 1
writeLine(p + " is a number that is perfect")
count++
end
k = kk + 1
kk += k
end
writeLine("There are " + count + " perfect numbers <= 35,000,000")
</syntaxhighlight>
{{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
Count of primes up to 100 = 25
Count of primes up to 1000 = 168
Count of primes up to 10000 = 1229
Count of primes up to 100000 = 9592
Count of primes up to 1000000 = 78498
Count of primes up to 10000000 = 664579
6 is a number that is perfect
28 is a number that is perfect
496 is a number that is perfect
8128 is a number that is perfect
33550336 is a number that is perfect
There are 5 perfect numbers <= 35,000,000
</pre>
 
226

edits