We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f869601 commit 6351bf2Copy full SHA for 6351bf2
Others/EulersFunction.java
@@ -0,0 +1,20 @@
1
+//You can read more about Euler's totient function https://en.wikipedia.org/wiki/Euler%27s_totient_function
2
+public class EulersFunction {
3
+ //This method returns us number of x that (x < n) and gcd(x, n) == 1 in O(sqrt(n)) time complexity;
4
+ public static int getEuler(int n) {
5
+ int result = n;
6
+ for (int i = 2; i * i <= n; i++) {
7
+ if(n % i == 0) {
8
+ while (n % i == 0) n /= i;
9
+ result -= result / i;
10
+ }
11
12
+ if (n > 1) result -= result / n;
13
+ return result;
14
15
+ public static void main(String[] args) {
16
+ for(int i = 1; i < 100; i++) {
17
+ System.out.println(getEuler(i));
18
19
20
+}
0 commit comments