Program to calculate Euler's Totient Function.
All checks were successful
The build was successful.

This commit is contained in:
Rafal Kupiec 2019-04-20 14:17:06 +02:00
förälder ed8f3f341e
incheckning 8331d36869
Signerad av: belliash
GPG-nyckel ID: 4E829243E0CFE6B4
2 ändrade filer med 39 tillägg och 0 borttagningar

29
tests/eulers_totient.aer Normal file
Visa fil

@ -0,0 +1,29 @@
// A simple C program to calculate Euler's Totient Function
class Program {
// Function to return gcd of a and b
private int gcd(int $a, int $b) {
if($a == 0)
return $b;
return $this->gcd($b % $a, $a);
}
// A simple method to evaluate Euler Totient Function
private int phi(int $n) {
int $result = 1;
for(int $i = 2; $i < $n; $i++)
if($this->gcd($i, $n) == 1)
$result++;
return $result;
}
// Driver program to test above function
public int main() {
int $n;
for($n = 1; $n <= 10; $n++)
printf("phi(%d) = %d\n", $n, $this->phi($n));
return 0;
}
}

10
tests/eulers_totient.exp Normal file
Visa fil

@ -0,0 +1,10 @@
phi(1) = 1
phi(2) = 1
phi(3) = 2
phi(4) = 2
phi(5) = 4
phi(6) = 2
phi(7) = 6
phi(8) = 4
phi(9) = 6
phi(10) = 4