Jump to content

Perfect totient numbers: Difference between revisions

Add CLU
(Added AutoHotkey)
(Add CLU)
Line 369:
3 9 15 27 39 81 111 183 243 255 327 363 471 729 2187 2199 3063 4359 4375 5571
</pre>
=={{header|CLU}}==
<lang clu>gcd = proc (a, b: int) returns (int)
while b ~= 0 do
a, b := b, a//b
end
return(a)
end gcd
 
totient = proc (n: int) returns (int)
tot: int := 0
for i: int in int$from_to(1,n-1) do
if gcd(n,i)=1 then tot := tot + 1 end
end
return(tot)
end totient
 
perfect = proc (n: int) returns (bool)
sum: int := 0
x: int := n
while true do
x := totient(x)
sum := sum + x
if x=1 then break end
end
return(sum = n)
end perfect
 
start_up = proc ()
po: stream := stream$primary_output()
seen: int := 0
n: int := 3
while seen < 20 do
if perfect(n) then
stream$puts(po, int$unparse(n) || " ")
seen := seen + 1
end
n := n + 2
end
end start_up</lang>
{{out}}
<pre>3 9 15 27 39 81 111 183 243 255 327 363 471 729 2187 2199 3063 4359 4375 5571</pre>
=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";
2,114

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.