Data update
This commit is contained in:
parent
8f05c7136f
commit
0bf4da02c3
82 changed files with 2194 additions and 118 deletions
41
Task/Totient-function/PL-I/totient-function.pli
Normal file
41
Task/Totient-function/PL-I/totient-function.pli
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
totientFunction: procedure options(main);
|
||||
totient: procedure(nn) returns(fixed);
|
||||
declare (nn, n, i, tot) fixed;
|
||||
n = nn;
|
||||
tot = n;
|
||||
do i=2 repeat(i+2) while(i*i <= n);
|
||||
if mod(n,i) = 0 then do;
|
||||
do while(mod(n,i) = 0);
|
||||
n = n / i;
|
||||
end;
|
||||
tot = tot - tot / i;
|
||||
end;
|
||||
if i=2 then i=1;
|
||||
end;
|
||||
if n>1 then tot = tot - tot/n;
|
||||
return(tot);
|
||||
end totient;
|
||||
|
||||
showPrimeCount: procedure(n, primeCount);
|
||||
declare (n, primeCount) fixed;
|
||||
put skip edit('There are', primeCount, ' primes up to', n) (A,F(5),A,F(6));
|
||||
end showPrimeCount;
|
||||
|
||||
declare (n, primeCount, tot) fixed;
|
||||
do n = 1 to 25;
|
||||
tot = totient(n);
|
||||
put edit('phi(', n, ') = ', tot) (A,F(2),A,F(2));
|
||||
if tot = n-1 then do;
|
||||
put list('; prime');
|
||||
primeCount = primeCount + 1;
|
||||
end;
|
||||
put skip;
|
||||
end;
|
||||
|
||||
call showPrimeCount(25, primeCount);
|
||||
do n = 26 to 10000;
|
||||
if totient(n) = n-1 then primeCount = primeCount + 1;
|
||||
if n=100 | n=1000 | n=10000 then
|
||||
call showPrimeCount(n, primeCount);
|
||||
end;
|
||||
end totientFunction;
|
||||
Loading…
Add table
Add a link
Reference in a new issue