Data update
This commit is contained in:
parent
8f05c7136f
commit
0bf4da02c3
82 changed files with 2194 additions and 118 deletions
62
Task/Totient-function/Modula-2/totient-function.mod2
Normal file
62
Task/Totient-function/Modula-2/totient-function.mod2
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
MODULE TotientFunction;
|
||||
FROM InOut IMPORT WriteString, WriteCard, WriteLn;
|
||||
|
||||
VAR count, n, tot: CARDINAL;
|
||||
|
||||
PROCEDURE totient(n: CARDINAL): CARDINAL;
|
||||
VAR tot, i: CARDINAL;
|
||||
BEGIN
|
||||
tot := n;
|
||||
i := 2;
|
||||
WHILE i*i <= n DO
|
||||
IF n MOD i = 0 THEN
|
||||
WHILE n MOD i = 0 DO
|
||||
n := n DIV i
|
||||
END;
|
||||
DEC(tot, tot DIV i)
|
||||
END;
|
||||
IF i=2 THEN i := 1 END;
|
||||
INC(i, 2)
|
||||
END;
|
||||
IF n>1 THEN
|
||||
DEC(tot, tot DIV n)
|
||||
END;
|
||||
RETURN tot
|
||||
END totient;
|
||||
|
||||
PROCEDURE ShowPrimeCount(n, count: CARDINAL);
|
||||
BEGIN
|
||||
WriteString("Number of primes up to");
|
||||
WriteCard(n, 6);
|
||||
WriteString(": ");
|
||||
WriteCard(count, 4);
|
||||
WriteLn
|
||||
END ShowPrimeCount;
|
||||
|
||||
BEGIN
|
||||
count := 0;
|
||||
|
||||
WriteString(" N Totient Prime");
|
||||
WriteLn;
|
||||
FOR n := 1 TO 25 DO
|
||||
tot := totient(n);
|
||||
WriteCard(n, 2);
|
||||
WriteCard(tot, 9);
|
||||
IF tot = n-1 THEN
|
||||
WriteString(" Yes");
|
||||
INC(count)
|
||||
ELSE
|
||||
WriteString(" No")
|
||||
END;
|
||||
WriteLn
|
||||
END;
|
||||
|
||||
ShowPrimeCount(25, count);
|
||||
|
||||
FOR n := 26 TO 10000 DO
|
||||
IF totient(n) = n-1 THEN INC(count) END;
|
||||
IF (n=100) OR (n=1000) OR (n=10000) THEN
|
||||
ShowPrimeCount(n, count)
|
||||
END;
|
||||
END
|
||||
END TotientFunction.
|
||||
Loading…
Add table
Add a link
Reference in a new issue