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

来源:互联网 发布:plc编程功能块 编辑:程序博客网 时间:2024/06/06 00:59

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");    }}
阅读全文
1 0