题目
思路:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int maxn = 1e6 + 5, inf = 1e9 + 5, maxm = 4e4 + 5, mod = 1e9 + 7, N = 1e6;
// int a[maxn], b[maxn];
int n, m;
string s;int qpow(int a, int b){int res = 1;while(b){if(b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res;
}int __lcm(int a, int b){int g = __gcd(a, b);return a * b / g;
}void solve()
{int res = 0;int a, b, c, p, q, r, x, y, z;cin >> b >> q >> y >> c >> r >> z;int b2 = b + (y - 1) * q, c2 = c + (z - 1) * r;if(!(b <= c && b2 >= c2 && r % q == 0 && (c - b) % q == 0)){cout << "0\n";return;}if(b > c - r || b2 < c2 + r){cout << "-1\n";return;}for(int i = 1; i * i <= r; i++){if(r % i == 0){if(__lcm(i, q) == r)res = (res + (r / i) * (r / i) % mod) % mod; }if(r / i != i && __lcm(r / i, q) == r){int p = r / i;res = (res + r / p * (r / p) % mod) % mod;}}cout << res << '\n';
}
signed main(){ios::sync_with_stdio(0);cin.tie(0);// fac[0] = 1;// for(int i = 1; i <= N; i++){// fac[i] = fac[i - 1] * i % mod;// }int T = 1;cin >> T;while (T--){solve();}return 0;
}