青蛙的约会 java版

参考http://blog.csdn.net/polossk/article/details/9799735

 

package acm;

public class FrogDate {

    public static void main(String[] args) {
        
        int x = 11,y = 21,m = 31,n = 41,l = 44;
        int ar=n-m,br=0,cr=x-y;
        int M = exGcd(n-m,l,ar,br);

        System.out.println("M:" + M);
        
        if((x-y)%M!=0 || m==n) 
            System.out.println("Impossible");
        else{  
            int s=l/M;  
            ar=ar*((x-y)/M);              ar=(ar%s+s)%s;  
            System.out.println("ar : " + ar);
        }
    }
    
    static int Gcd(int a, int b)  
    {  
        while(b != 0)  
        {  
            int r = b;  
            b = a % b;  
            a = r;  
        }  
        return a;  
    }
    
    static int exGcd(int a, int b, int x, int y)  
    {
        if(b == 0)  
        {  
            x = 1;  
            y = 0;  
            return a;  
        }  
        int r = exGcd(b, a % b, x, y);  
        int t = x;  
        x = y;  
        y = t - a / b * y;  
        return r;  
    } 
    
}

 

青蛙的约会 java版,布布扣,bubuko.com

青蛙的约会 java版

上一篇:Java补漏(一)


下一篇:java学习-关于字符串String