topic
Commentary
The title name is great!
This question is a thinking / math question. It is really easy to understand.
A number can be obtained by multiplying many numbers, and each number that makes up it is like its components. Multiplying a number by \ (k \) is equivalent to adding \ (k \) to its composition . Then we look at this question.
Assuming that the two people are \ (AB \) and the initials are both \ (1 \) , then multiplying \ (A \) by k in a round of game is to add \ (k \) to its composition, and at the same time in \ (B \) component added two \ (k \) , \ (AB \) total added three \ (k \) . Obviously \ (A × B \) is equivalent to mixing \ (AB \) together, all its ingredients are mixed together, so \ (A × B \) must contain three \ (k \) . Then we only need to judge whether \ (A × B \) is a complete cubic number.
So I wrote the first generation of code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read(){
char ch=getchar();
ll s=0,f=1;
while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9') {s=(s<<3)+(s<<1)+ch-'0';ch=getchar();}
return s*f;
}
int main(){
int T;
cin>>T;
while(T--){
ll a,b;
a=read();b=read();
ll u=a*b;
ll m=pow(u,(1.0/3))+0.5;//计算立方根
//注意变为整数时+0.5四舍五入
if(m*m*m!=u) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
return 0;
}
Afternoon WA completion ……
Where is the problem? Oh, we ignored a situation. If we put all three \ (k \) into a number, then my program will output \ (Yes \) , but in fact this is not eligible. We also need to add a layer of conditions, that is, the cube root is a factor of two numbers \ (AB \) .
Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read(){
char ch=getchar();
ll s=0,f=1;
while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9') {s=(s<<3)+(s<<1)+ch-'0';ch=getchar();}
return s*f;
}
int main(){
int T;
cin>>T;
while(T--){
ll a,b;
a=read();b=read();
ll u=a*b;
ll m=pow(u,(1.0/3))+0.5;
if(m*m*m!=u||a%m||b%m) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
return 0;
}