Perfect totient numbers: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) |
(Perfect totient numbers in BASIC256) |
||
Line 243: | Line 243: | ||
327 363 471 729 2187 |
327 363 471 729 2187 |
||
2199 3063 4359 4375 5571</pre> |
2199 3063 4359 4375 5571</pre> |
||
=={{header|BASIC256}}== |
|||
{{trans|FreeBASIC}} |
|||
<lang freebasic>found = 0 |
|||
curr = 3 |
|||
while found < 20 |
|||
sum = Totient(curr) |
|||
toti = sum |
|||
while toti <> 1 |
|||
toti = Totient(toti) |
|||
sum += toti |
|||
end while |
|||
if sum = curr then |
|||
print sum |
|||
found += 1 |
|||
end if |
|||
curr += 1 |
|||
end while |
|||
end |
|||
function GCD(n, d) |
|||
if n = 0 then return d |
|||
if d = 0 then return n |
|||
if n > d then return GCD(d, (n mod d)) |
|||
return GCD(n, (d mod n)) |
|||
end function |
|||
function Totient(n) |
|||
phi = 0 |
|||
for m = 1 to n |
|||
if GCD(m, n) = 1 then phi += 1 |
|||
next m |
|||
return phi |
|||
end function</lang> |
|||
=={{header|BCPL}}== |
=={{header|BCPL}}== |