Advertisement
AmidamaruZXC

Untitled

Oct 14th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1.     public static int gcd(int x, int y)
  2.     {
  3.         int t;
  4.  
  5.         if(x < 0) x = -x;
  6.         if(y < 0) y = -y;
  7.  
  8.         while(y != 0)
  9.         {
  10.             if(y > x)
  11.             {
  12.                 x = y-x;
  13.                 y = y-x;
  14.                 x = x+y;
  15.             }
  16.  
  17.             if(y == 0) return x;
  18.  
  19.             t = y;
  20.             y = x%y;
  21.             x = t;
  22.         }
  23.         return Math.abs(x);
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement