pku 1061 青蛙的约会 同余方程

 #include<cstdio> long long mod(long long a,long long b) { return (a % b + b) % b; } struct triple { long long d,x,y; }; long long Euclid(long long a,long long b) { if(b == 0) return a; else return Euclid(b,mod(a,b)); } triple Extended_Euclid(long long a,long long b) { triple result; if(b == 0) { result.d = a; result.x = 1; result.y = 0; } else { triple ee = Extended_Euclid(b,mod(a,b)); result.d = ee.d; result.x = ee.y; result.y = ee.x - (a/b)*ee.y; } return result; } long long MLES(long long a,long long b,long long n) { triple ee = Extended_Euclid(a,n); if(mod(b,ee.d) == 0) return mod((ee.x * (b / ee.d)),n/ee.d); else return -1; } int main() { long long x, y, m, n, L; scanf("%I64d%I64d%I64d%I64d%I64d", &x, &y, &m, &n, &L); long long ret; ret = MLES(m-n, y-x, L); if (ret == -1) { printf("Impossible/n"); } else printf("%I64d/n", ret); }

你可能感兴趣的:(struct)