Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

29 lines
590 B

// 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;
}
}