标签:acm codeforces 数学
void ex_gcd(LL a, LL b, LL &x, LL &y, LL &d) { if (!b) x = 1, y = 0, d = a; else { ex_gcd(b, a % b, y, x, d); y -= x * (a / b); } } int main() { //freopen("0.txt", "r", stdin); int T; RI(T); FE(kase, 1, T) { LL n1, n2, f1, f2, d1, d2; LL a, b, v, x, y, dx, dy, gcd; cin >> n1 >> f1 >> d1 >> n2 >> f2 >> d2; a = d1, b = -d2, v = d1 - d2 + f2 - f1; ex_gcd(a, b, x, y, gcd); if (v % gcd != 0) puts("0"); else { x *= v / gcd; x = f1 + (x - 1) * d1; dx = b / gcd * d1; x = ((x - 1) % dx + dx) % dx + 1; y = min(f1 + (n1 - 1) * d1, f2 + (n2 - 1) * d2); if (x <= y) cout << (y - x) / dx + 1 << endl; else puts("0"); } } return 0; }
标签:acm codeforces 数学
原文地址:http://blog.csdn.net/wty__/article/details/37995731