Jiangxi University of Finance and Economics The First Programming Contest I Questions Small P and Small Q

Topic link: https://www.nowcoder.com/acm/contest/115/I

Be careful with this topic! ! ! The mandatory type conversion before the pow function must be float!!! It must be float, not double, otherwise the data will be wrong, and the same is true for the cbrt function! ! !

Problem-solving idea: The k of each round is different, so let's look for the rules. Suppose at the end a gets x1 points and b gets x2 points. Assuming that a wins two games and b wins one game, can we split x1 into x1= k1 2 *k2 2 *k3, then x2=k1*k2*k 3 .

Then there is (x1*x2) 1/3 ==n (n is a positive integer).

This question also needs to be judged specially, such as a 1 point, b 8 points. Although the third power is 2, it is a positive integer, but it cannot be obtained. Background data is also not stuck on this point.

AC code:

 1 #include<iostream>
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 int main(){
 5     int t;
 6     cin>>t;
 7     while(t--){
 8         long long a,b;
 9         cin>>a>>b;
10         long long c=a*b;
11         if(a==1&&b==1){
12             cout<<"Yes"<<endl;
13         } else  if (a== 1 &&b!= 1 ){
 14              cout<< " No " << endl;
 15          } else  if (a!= 1 &&b== 1 ){
 16              cout<< " No " << endl ;
 17          } else {
 18              long  long ans=( float )pow(c, 1.0 / 3.0 );   // float !!! Must be float, not double, otherwise the data will go wrong, and the same is true for the cbrt function! ! !
19             long long va=ans*ans*ans; 
20             if(va==c){
21                 cout<<"Yes"<<endl;
22             }else{
23                 cout<<"No"<<endl;
24             }
25         }
26     }
27     return 0;
28 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324639249&siteId=291194637