Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
42
Task/Totient-function/XPL0/totient-function.xpl0
Normal file
42
Task/Totient-function/XPL0/totient-function.xpl0
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
func GCD(N, D); \Return the greatest common divisor of N and D
|
||||
int N, D; \numerator and denominator
|
||||
int R;
|
||||
[if D > N then
|
||||
[R:= D; D:= N; N:= R]; \swap D and N
|
||||
while D > 0 do
|
||||
[R:= rem(N/D);
|
||||
N:= D;
|
||||
D:= R;
|
||||
];
|
||||
return N;
|
||||
]; \GCD
|
||||
|
||||
func Totient(N); \Return the totient of N
|
||||
int N, Phi, M;
|
||||
[Phi:= 0;
|
||||
for M:= 1 to N do
|
||||
if GCD(M, N) = 1 then Phi:= Phi+1;
|
||||
return Phi;
|
||||
];
|
||||
|
||||
int N, Phi, Pwr, C, Limit;
|
||||
[Text(0, "n phi is prime^m^j");
|
||||
for N:= 1 to 25 do
|
||||
[IntOut(0, N); ChOut(0, 9\tab\);
|
||||
Phi:= Totient(N);
|
||||
IntOut(0, Phi); ChOut(0, 9\tab\);
|
||||
Text(0, if Phi = N-1 then "true" else "false");
|
||||
CrLf(0);
|
||||
];
|
||||
CrLf(0);
|
||||
for Pwr:= 2 to 4 do
|
||||
[C:= 0;
|
||||
Limit:= fix(Pow(10.0, float(Pwr)));
|
||||
IntOut(0, Limit); ChOut(0, 9\tab\);
|
||||
for N:= 1 to Limit do
|
||||
[Phi:= Totient(N);
|
||||
if Phi = N-1 then C:= C+1;
|
||||
];
|
||||
IntOut(0, C); CrLf(0);
|
||||
];
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue