#include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #pragma comment(linker, "/STACK:102400000,102400000") #define ll long long #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a,x) memset(a,x,sizeof(a)) #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) #define lrt (rt<<1) #define rrt (rt<<1|1) using namespace std; const long long INF = 1e18+1LL; const int inf = 1e9+1e8; const int N=1e6+100; const ll mod=1e9+7; ll n,a,b,c; int main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n; for(int i=1; i<=n; ++i){ cin>>a>>b; c=a*b; ll l=1, r=1e6,ans=0; while(l<=r){ ll mid=l+r>>1; if(mid*mid*mid==c){ ans=mid; break; } else if(mid*mid*mid>c){ r=mid-1; } else l=mid+1; } if(ans && a%ans==0 && b%ans==0) cout<<"Yes "; else cout<<"No "; } return 0; }
题意:2个人玩游戏,每一轮赢的人的数乘以k^2,输的人乘k(每一轮的k可以不一样,2人初始分数都为1),经行若干轮之后,2人的分数分别为a,b,给出a,b,问这样的得分是否合理
思路:每一轮之后每一轮赢的人的数乘以k^2,输的人乘k,那么2人的分数相乘就是若干个k^3的乘积,所以a*b若是某个数的三次方,并且a和b都能整除这个数说明是合理的
AC代码: