40 lines
922 B
Plaintext
40 lines
922 B
Plaintext
proc totient(word n) word:
|
|
word tot, i;
|
|
tot := n;
|
|
i := 2;
|
|
while i*i <= n do
|
|
if n%i = 0 then
|
|
while n%i = 0 do n := n/i od;
|
|
tot := tot - tot/i
|
|
fi;
|
|
if i=2 then i:=1 fi;
|
|
i := i+2
|
|
od;
|
|
if n>1 then
|
|
tot - tot/n
|
|
else
|
|
tot
|
|
fi
|
|
corp
|
|
|
|
proc main() void:
|
|
word count, n, tot;
|
|
bool prime;
|
|
|
|
count := 0;
|
|
writeln(" N Totient Prime");
|
|
for n from 1 upto 25 do
|
|
tot := totient(n);
|
|
prime := n-1 = tot;
|
|
if prime then count := count+1 fi;
|
|
writeln(n:2, " ", tot:7, " ", if prime then " Yes" else " No" fi)
|
|
od;
|
|
writeln("Number of primes up to ",25:6,": ",count:4);
|
|
for n from 25 upto 10000 do
|
|
if totient(n) = n-1 then count := count+1 fi;
|
|
if n=100 or n=1000 or n=10000 then
|
|
writeln("Number of primes up to ",n:6,": ",count:4)
|
|
fi
|
|
od
|
|
corp
|