Codeforces Round #426 (Div. 2)C. The Meaningless Game
题意:AB两个人,每一轮,其中一人选择一个数字K,那么A就变成A*k*k,B就变成B*K,给出结果,问是否可能
思路:不管多少轮,A*B结果都是某个数的立方,二分
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=1e5+10,M=1e6+10,inf=1e9+7,MOD=1e9+7; 5 const ll INF=1e18+10,mod=1e9+7; 6 7 8 int main() 9 { 10 int T; 11 scanf("%d",&T); 12 while(T--) 13 { 14 ll a,b; 15 scanf("%lld%lld",&a,&b); 16 ll l=1,r=1e6+10,ans=-1; 17 while(l<=r) 18 { 19 ll mid=(l+r)/2; 20 if(mid*mid*mid<=a*b) 21 { 22 ans=mid; 23 l=mid+1; 24 } 25 else r=mid-1; 26 } 27 if(ans*ans*ans==a*b&&a%ans==0&&b%ans==0)printf("Yes\n"); 28 else printf("No\n"); 29 } 30 return 0; 31 }