这题竟然暴力就过了……
在[1, sqrt(b1)]中枚举x,判断x | b1,如果成立,再判断lcm(x, b0) == b1 && gcd(x, a0) == a1,并计数。
复杂度O(n * sqrt(b1) * logb1)。
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cmath> 5 #include<cstring> 6 #include<cstdlib> 7 #include<cctype> 8 #include<stack> 9 #include<queue> 10 #include<vector> 11 using namespace std; 12 #define enter puts("") 13 #define space putchar(' ') 14 #define Mem(a, x) memset(a, x, sizeof(a)) 15 #define rg register 16 typedef long long ll; 17 typedef double db; 18 const int INF = 0x3f3f3f3f; 19 const db eps = 1e-8; 20 //const int maxn = ; 21 inline ll read() 22 { 23 ll ans = 0; 24 char ch = getchar(), las = ' '; 25 while(!isdigit(ch)) las = ch, ch = getchar(); 26 while(isdigit(ch)) ans = ans * 10 + ch - '0', ch = getchar(); 27 if(las == '-') ans = -ans; 28 return ans; 29 } 30 inline void write(ll x) 31 { 32 if(x < 0) putchar('-'), x = -x; 33 if(x >= 10) write(x / 10); 34 putchar(x % 10 + '0'); 35 } 36 37 int n; 38 ll a0, a1, b0, b1; 39 40 ll gcd(ll a, ll b) 41 { 42 return b ? gcd(b, a % b) : a; 43 } 44 45 int main() 46 { 47 n = read(); 48 for(int i = 1; i <= n; ++i) 49 { 50 a0 = read(); a1 = read(); b0 = read(); b1 = read(); 51 int cnt = 0; 52 for(int j = 1; j * j <= b1; ++j) 53 { 54 if(!(b1 % j)) 55 { 56 ll Lcm1 = j / gcd(j, b0) * b0, Gcd1 = gcd(j, a0); 57 ll Lcm2 = b1 / j / gcd(b1 / j, b0) * b0, Gcd2 = gcd(b1 / j, a0); 58 if(j * j == b1) 59 { 60 if(Lcm1 == b1 && Gcd1 == a1) cnt++; 61 } 62 else 63 { 64 if(Lcm1 == b1 && Gcd1 == a1) cnt++; 65 if(Lcm2 == b1 && Gcd2 == a1) cnt++; 66 } 67 } 68 } 69 write(cnt); enter; 70 } 71 return 0; 72 }