Codeforces Round #426 (Div. 2) C:The Meaningless Game(思維)

C. The Meaningless Game
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output

Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.

The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner’s score is multiplied by k2, and the loser’s score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.

Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not.

Input
In the first string, the number of games n (1 ≤ n ≤ 350000) is given.

Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly.

Output
For each pair of scores, answer “Yes” if it’s possible for a game to finish with given score, and “No” otherwise.

You can output each letter in arbitrary case (upper or lower).

Example
input
6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000
output
Yes
Yes
Yes
No
No
Yes
Note
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.

The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
題意:現在有兩個人玩遊戲,一開始兩個人的分數都是1,每一輪遊戲兩個人會共同挑選一個數K,遊戲獲得勝利的選手將自己的分數 *k^2,輸了的選手將自己的分數*k.現在有n個查詢,每個查詢表示兩個人最終的分數,問是否有一種遊戲過程,使得這個最終分數是可能出現的。
題解:
首先a*b一定是一個立方數,但是不一定滿足,例如2,32.所以a,b一定得能整出這個立方數開三次方。
代碼:

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#include<map>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int>pa;
const int N=1e5+10;
const int mod=1e9+7;
const ll INF=1e18;
int read()
{
    int x=0;
    char ch = getchar();
    while('0'>ch||ch>'9')ch=getchar();
    while('0'<=ch&&ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return x;
}
/***********************************************************/
map<ll,int>s;
int t;
ll a,b;
void init()
{

    for(ll i=1; i<=1000000; i++)
    {
        ll tmp=i*i*i;
        s[tmp]=i;
    }
}
int main()
{
    init();
    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d%I64d",&a,&b);
        ll c=a*b;
        if(s[c]>0)
        {
            ll tmpp=s[c];
            if(a%tmpp==0&&b%tmpp==0)puts("Yes");
            else puts("No");
        }
        else puts("No");
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章