luogu P1072 Hankson 的趣味題
阿新 • • 發佈:2018-11-08
日漸熟練了
從已知條件搞一搞就可以發現a1|x , x|b1
於是考慮列舉約數
O(sqrt(n)*lgn*T)差不多1e7 被ll卡一波常數
考試的時候實在卡常的話 也一定要看清楚
該開longlong的不能少
Code:
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 #include<queue> 6 #include<vector> 7#include<iostream> 8 #include<iomanip> 9 #define itn int 10 #define ms(a,b) memset(a,b,sizeof a) 11 #define rep(i,a,n) for(int i = a;i <= n;i++) 12 #define per(i,n,a) for(int i = n;i >= a;i--) 13 #define inf 2147483647 14 using namespace std; 15 typedef long long ll; 16 ll read() {17 ll as = 0,fu = 1; 18 char c = getchar(); 19 while(c < '0' || c > '9') { 20 if(c == '-') fu = -1; 21 c = getchar(); 22 } 23 while(c >= '0' && c <= '9') { 24 as = as * 10 + c - '0'; 25 c = getchar(); 26 } 27 return as * fu; 28} 29 //head 30 int a1,b1,a2,b2; 31 int gcd(int a,int b) {return b ? gcd(b,a%b) : a;} 32 33 bool judge(int x) { 34 x *= a2; 35 if(gcd(x,a1) == a2 && (ll)b2 * gcd(x,b1) == (ll)x * b1) return 1; 36 return 0; 37 } 38 39 void solve() { 40 int ans = 0; 41 a1 = read(),a2 = read(),b1 = read(),b2 = read(); 42 int t = b2 / a2; 43 rep(i,1,sqrt(t)) { 44 if(t % i) continue; 45 ans += judge(i); 46 if(i * i == t) continue; 47 ans += judge(t/i); 48 } 49 printf("%d\n",ans); 50 } 51 52 int main() { 53 int T = read(); 54 while(T--) solve(); 55 return 0; 56 }