标签:问题 ret 网上 位置 sub names scanf discuss 扩展欧几里得
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; long long x, y, m, n, L, ansx, ansy; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a%b); } long long exgcd(long long a, long long b, long long &x, long long&y) { if (b == 0) { x = 1; y = 0; return a; } long long r = exgcd(b, a%b, x, y); long long t = x; x = y; y = t - a / b * y; return r; } int main() { scanf("%lld%lld%lld%lld%lld", &x, &y, &m, &n, &L); if (x == y) { printf("0"); return 0; } else { long long a = m - n, b = y - x; long long t = exgcd(a, L, ansx, ansy); if (b % t == 0) { ansx = ansx * b / t; int tt = abs(L / t); ansx = (ansx % tt + tt) % tt; printf("%d", ansx); } else printf("Impossible"); } return 0; }
标签:问题 ret 网上 位置 sub names scanf discuss 扩展欧几里得
原文地址:http://www.cnblogs.com/zbtrs/p/7296409.html