RosettaCodeData/Task/Totient-function/EasyLang/totient-function.easy

31 lines
561 B
Text
Raw Permalink Normal View History

2025-02-27 18:35:13 -05:00
fastfunc totient n .
2023-09-16 17:28:03 -07:00
tot = n
i = 2
while i <= sqrt n
if n mod i = 0
2025-02-27 18:35:13 -05:00
while n mod i = 0 : n = n div i
2023-09-16 17:28:03 -07:00
tot -= tot div i
.
2025-02-27 18:35:13 -05:00
if i = 2 : i = 1
2023-09-16 17:28:03 -07:00
i += 2
.
2025-02-27 18:35:13 -05:00
if n > 1 : tot -= tot div n
2023-09-16 17:28:03 -07:00
return tot
.
2025-06-11 20:16:52 -04:00
numfmt 3 0
2023-09-16 17:28:03 -07:00
print " N Prim Phi"
for n = 1 to 25
tot = totient n
x$ = " "
2025-02-27 18:35:13 -05:00
if n - 1 = tot : x$ = " x "
2023-09-16 17:28:03 -07:00
print n & x$ & tot
.
print ""
for n = 1 to 100000
tot = totient n
2025-02-27 18:35:13 -05:00
if n - 1 = tot : cnt += 1
2023-09-16 17:28:03 -07:00
if n = 100 or n = 1000 or n = 10000 or n = 100000
print n & " - " & cnt & " primes"
.
.