51 lines
1.3 KiB
Plaintext
51 lines
1.3 KiB
Plaintext
totient = proc (n: int) returns (int)
|
|
tot: int := n
|
|
|
|
i: int := 2
|
|
while i*i <= n do
|
|
if n//i = 0 then
|
|
while n//i = 0 do
|
|
n := n/i
|
|
end
|
|
tot := tot-tot/i
|
|
end
|
|
if i=2 then i:=1 end
|
|
i := i+2
|
|
end
|
|
if n>1 then
|
|
tot := tot-tot/n
|
|
end
|
|
return(tot)
|
|
end totient
|
|
|
|
start_up = proc ()
|
|
po: stream := stream$primary_output()
|
|
count: int := 0
|
|
|
|
stream$putl(po, " N Totient Prime")
|
|
for n: int in int$from_to(1, 25) do
|
|
tot: int := totient(n)
|
|
stream$putright(po, int$unparse(n), 2)
|
|
stream$putright(po, int$unparse(tot), 9)
|
|
if n-1 = tot then
|
|
stream$putright(po, "Yes", 7)
|
|
count := count + 1
|
|
else
|
|
stream$putright(po, "No", 7)
|
|
end
|
|
stream$putl(po, "")
|
|
end
|
|
|
|
stream$putl(po, "Number of primes up to 25:\t" || int$unparse(count))
|
|
for n: int in int$from_to(26, 100000) do
|
|
if totient(n) = n-1 then
|
|
count := count + 1
|
|
end
|
|
if n = 100 cor n = 1000 cor n // 10000 = 0 then
|
|
stream$putl(po, "Number of primes up to "
|
|
|| int$unparse(n) || ":\t"
|
|
|| int$unparse(count))
|
|
end
|
|
end
|
|
end start_up
|