acm-青蛙的约会哦~

这个题目就是水题,叫我AC要经过很久苦逼代码,本人不细心,总是犯错。主要注意2点:原理就是欧几里德算法,其次算出来的结果可能是负数,依照具体的题目要求要稍稍变动一下。上代码,这次是AC的代码:

#include<iostream>
using namespace std;

long long x,y,m,n,L,q,x1,y1;
void  ex_gcd(long long a,long long b)
{
    if(b==0)
    {
        q=a;x1=1;y1=0;return;
    }
    else
    {
        long m = a%b;
        ex_gcd(b,m);
        long long temp=x1;
        x1=y1;
        y1=temp-a/b*x1;
    }
}
int main()
{
    long long a,b,c;
    cin >> x >> y >> m >> n >> L;

    if(m - n > 0)
    {
        b = m - n;
        c = y - x;
    }
    else
    {
        b = n - m;
        c  = x - y;
    }

        ex_gcd(b,L);
        if(c%q!=0)
        {
            cout << "Impossible" << endl;
            return 0;
        }
        a=x1*c/q;
        a%=L;

        if(a<0)
        {
            a+=L;
        }
       cout << a << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/hhhhhhhhhhhhhhhhhhhhhhhhhhh/p/3863432.html