@Test public void testTotient() { assertEquals( 1, Library.totient( 1)); assertEquals( 1, Library.totient( 2)); assertEquals( 2, Library.totient( 3)); assertEquals( 2, Library.totient( 4)); assertEquals( 4, Library.totient( 5)); assertEquals( 2, Library.totient( 6)); assertEquals( 6, Library.totient( 7)); assertEquals( 4, Library.totient( 8)); assertEquals( 6, Library.totient( 9)); assertEquals( 4, Library.totient(10)); assertEquals(10, Library.totient(11)); assertEquals( 4, Library.totient(12)); assertEquals(12, Library.totient(13)); assertEquals( 6, Library.totient(14)); assertEquals( 8, Library.totient(15)); assertEquals( 8, Library.totient(16)); assertEquals(16, Library.totient(17)); assertEquals( 6, Library.totient(18)); assertEquals(18, Library.totient(19)); assertEquals( 8, Library.totient(20)); }
public static int totient(int n) { if (n <= 0) throw new IllegalArgumentException("Totient of non-positive integer"); int p = 1; for (int i = 2, end = Library.sqrt(n); i <= end; i++) { if (n % i == 0) { p *= i - 1; n /= i; while (n % i == 0) { p *= i; n /= i; } end = Library.sqrt(n); } } if (n != 1) p *= n - 1; return p; }
Library { public static int totient(int n) { if (n <= 0) throw new IllegalArgumentException("Totient of non-positive integer"); int p = 1; for (int i = 2, end = Library.sqrt(n); i <= end; i++) { if (n % i == 0) { p *= i - 1; n /= i; while (n % i == 0) { p *= i; n /= i; } end = Library.sqrt(n); } } if (n != 1) p *= n - 1; return p; } }
Library { public static int totient(int n) { if (n <= 0) throw new IllegalArgumentException("Totient of non-positive integer"); int p = 1; for (int i = 2, end = Library.sqrt(n); i <= end; i++) { if (n % i == 0) { p *= i - 1; n /= i; while (n % i == 0) { p *= i; n /= i; } end = Library.sqrt(n); } } if (n != 1) p *= n - 1; return p; }  }
Library { public static int totient(int n) { if (n <= 0) throw new IllegalArgumentException("Totient of non-positive integer"); int p = 1; for (int i = 2, end = Library.sqrt(n); i <= end; i++) { if (n % i == 0) { p *= i - 1; n /= i; while (n % i == 0) { p *= i; n /= i; } end = Library.sqrt(n); } } if (n != 1) p *= n - 1; return p; }  static String reverse(String s); static boolean isPalindrome(String s); static boolean isPalindrome(int x); static int sqrt(int x); static long sqrt(long x); static BigInteger sqrt(BigInteger x); static boolean isSquare(int x); static int pow(int x, int y); static int powMod(int x, int y, int m); static int reciprocalMod(int x, int m); static BigInteger factorial(int n); static BigInteger binomial(int n, int k); static int gcd(int x, int y); static boolean isPrime(int x); static boolean[] listPrimality(int n); static int[] listPrimes(int n); static int[] listSmallestPrimeFactors(int n); static int totient(int n); static int[] listTotients(int n); static boolean nextPermutation(int[] arr); }
Library { public static int totient(int n) { if (n <= 0) throw new IllegalArgumentException("Totient of non-positive integer"); int p = 1; for (int i = 2, end = Library.sqrt(n); i <= end; i++) { if (n % i == 0) { p *= i - 1; n /= i; while (n % i == 0) { p *= i; n /= i; } end = Library.sqrt(n); } } if (n != 1) p *= n - 1; return p; }  static String reverse(String s); static boolean isPalindrome(String s); static boolean isPalindrome(int x); static int sqrt(int x); static long sqrt(long x); static BigInteger sqrt(BigInteger x); static boolean isSquare(int x); static int pow(int x, int y); static int powMod(int x, int y, int m); static int reciprocalMod(int x, int m); static BigInteger factorial(int n); static BigInteger binomial(int n, int k); static int gcd(int x, int y); static boolean isPrime(int x); static boolean[] listPrimality(int n); static int[] listPrimes(int n); static int[] listSmallestPrimeFactors(int n); static int totient(int n); static int[] listTotients(int n); static boolean nextPermutation(int[] arr);  }