waltermilner

Untitled

May 26th, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. public class Test {
  2.  
  3.   public static void main(String[] args) {
  4.  
  5.   System.out.println(phi(300));
  6.    
  7.   }
  8.  
  9.   public static int phi(int n)
  10.   {
  11.     int count=0;
  12.     for (int i=1; i<n; i++)
  13.       if (relPrime(i,n)) count++;
  14.     return count;
  15.   }
  16.   public static boolean relPrime(int a, int b)
  17.   {
  18.     int smaller = a<b?a:b;
  19.     for (int n=2; n<=smaller; n++)
  20.     {
  21.       if (a%n==0 && b%n==0)
  22.         return false;
  23.     }
  24.     return true;
  25.   }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment