We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 052ae3a commit 305e48dCopy full SHA for 305e48d
Math/eulers_totient_function/Java/etf.java
@@ -0,0 +1,34 @@
1
+// A simple java program to calculate
2
+// Euler's Totient Function
3
+import java.io.*;
4
+
5
+class GFG {
6
7
+ // Function to return GCD of a and b
8
+ static int gcd(int a, int b)
9
+ {
10
+ if (a == 0)
11
+ return b;
12
+ return gcd(b % a, a);
13
+ }
14
15
+ // A simple method to evaluate
16
+ // Euler Totient Function
17
+ static int phi(int n)
18
19
+ int result = 1;
20
+ for (int i = 2; i < n; i++)
21
+ if (gcd(i, n) == 1)
22
+ result++;
23
+ return result;
24
25
26
+ // Driver code
27
+ public static void main(String[] args)
28
29
+ int n;
30
31
+ for (n = 1; n <= 10; n++)
32
+ System.out.println("phi(" + n + ") = " + phi(n));
33
34
+}
0 commit comments