fork download
  1. import java.util.*;
  2.  
  3. class Main
  4. {
  5. public static void main (String[] args) {
  6. Scanner in = new Scanner(System.in);
  7. long n, m;
  8. n = in.nextLong();
  9. m = in.nextLong();
  10. System.out.print(f(n, m));
  11. }
  12. static long f(long n, long m) {
  13. if (n % m == 0) return m;
  14. if (m % n == 0) return n;
  15. if (m > n) return f(m % n, n);
  16. else return f(n % m , m);
  17. }
  18. }
Success #stdin #stdout 0.06s 2184192KB
stdin
6 3
stdout
3