Chowla numbers: Difference between revisions

m
(Initial FutureBasic task solution added)
Line 1,387:
{{trans|Go}}
<syntaxhighlight lang="text">
procfastfunc chowla n . sum .
sum = 0
i = 2
while i * i <= n
if n mod i = 0
j = n div i
if i = j
sum += i
else
sum += i + j
.
.
. i += 1
i += 1.
return sum
.
.
proc sieve . c[] .
i = 3
while i * 3 <= len c[]
if c[i] = 0
call if chowla i h= 0
if h j = 03 * i
while j <= 3 *len ic[]
while j <= len c[j] = 1
c[ j] += 12 * i
j += 2 * i.
.
.
. i += 2
i += 2.
.
.
proc commatize n . s$ .
s$[] = strchars n
s$ = ""
l = len s$[]
for i = 1 to len s$[]
if i > 1 and l mod 3 = 0
s$ &= ","
.
l -= 1
s$ &= s$[i]
.
.
print "chowla number from 1 to 37"
for i = 1 to 37
print " " & i & ": " & hchowla i
call chowla i h
print " " & i & ": " & h
.
proc main . .
print ""
len c[] 10000000
count = 1
call sieve c[]
power = 100
i = 3
while i <= len c[]
if c[i] = 0
count += 1
.
if i = power - 1
call commatize power p$
call commatize count c$
print "There are " & c$ & " primes up to " & p$
power *= 10
.
i += 2
.
print ""
limit = 35000000
count = 0
i = 2
k = 2
kk = 3
repeat
p = k * kk
until p > limit
call if chowla p h= p - 1
if h = p - 1commatize p s$
print s$ & " is a perfect number"
call commatize p s$
print s$ & "count is+= a perfect number"1
count += 1.
. k = kk + 1
k = kk += 1k
kk i += k1
i += 1.
call commatize plimit s$
.
print "There are " & count & " perfect mumbers up to " & s$
call commatize limit s$
print "There are " & count & " perfect mumbers up to " & s$
.
call main
1,983

edits