Sumar and the Floating Rocks

  • + 0 comments
    int a,b,c,d;
    BigInteger ans;
    // for x axis
    if(x1>x2){
        a=x2;
        b=x1;
    }else{
        a=x1;
        b=x2;
    }
    // for y axis
    if(y1>y2){
        c=y2;
        d=y1;
    }else{
        c=y1;
        d=y2;
    }
    // difference 
    BigInteger x=new BigInteger(String.valueOf(b-a));
    BigInteger y=new BigInteger(String.valueOf(d-c));
    // gcd calculation
    ans=x.gcd(y);
    int i= ans.intValue();
    
    return i-1;