Chowla numbers: Difference between revisions

Initial FutureBasic task solution added
(Initial FutureBasic task solution added)
Line 1,864:
Pulsa una tecla para salir
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn Chowla( n as NSUInteger ) as NSUInteger
NSUInteger i, j, r = 0
i = 2
while ( i * i <= n )
j = n / i
if ( n mod i == 0 )
r += i
if ( i != j )
r += j
end if
end if
i++
wend
end fn = r
 
local fn DoIt
NSUInteger n, count = 0, power = 100, limit, k, kk, p = 0
for n = 1 to 37
printf @"chowla(%u) = %u", n, fn Chowla( n )
next
for n = 2 to 10000000
if ( fn Chowla(n) == 0 ) then count ++
if ( n mod power == 0 ) then printf @"There are %u primes < %-7u", count, power : power *= 10
next
count = 0
limit = 350000000
k = 2 : kk = 3
do
p = k * kk
if ( fn Chowla( p ) == p - 1 )
printf @"%9u is a perfect number", p
count++
end if
k = kk + 1
kk = kk + k
until ( p > limit )
printf @"There are %u perfect numbers < %u", count, limit
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
{{output}}
<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 < 100
There are 168 primes < 1,000
There are 1,229 primes < 10,000
There are 9,592 primes < 100,000
There are 78,498 primes < 1,000,000
There are 664,579 primes < 10,000,000
6 is a perfect number
28 is a perfect number
496 is a perfect number
8,128 is a perfect number
33,550,336 is a perfect number
There are 5 perfect numbers < 35,000,000
</pre>
 
 
=={{header|Go}}==
<syntaxhighlight lang="go">package main
717

edits