gcd.mj 438 Bytes
Newer Older
uwwrp's avatar
uwwrp committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
class GCD {
    public static void main(String[] args) {
        GCD tmp = new GCD();
        int a = System.in.read();
        int b = System.in.read();

        System.out.write(tmp.gcd(a,b));
        System.out.flush();
    }

    public int gcd(int a, int b) {
        if(a <= 0 && b <= 0) return -1;

        int t;
        while(b != 0) {
          t = a % b;
          a = b;
          b = t;
        }

        return a;
    }
}