概述
题目:
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).
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.
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.
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).
题目大意:现在有两个人玩游戏,一开始两个人的分数都是1,每一轮游戏两个人会共同挑选一个数k,游戏获得胜利的选手将自己的分数 *k^2,输了的选手将自己的分数*k.现在有n个查询,每个查询表示两个人最终的分数,问是否有一种游戏过程,使得这个最终分数是可能出现的。
思路:
观察可发现如下特征:
1.a*b=(k1k2k3...kn)^3。
2.(k1k2k3...kn)能整除a,b。
证明:
代码:#include <stdio.h>
#include <stdlib.h>
#include <iostream>
long long a,b;
int n;
int main()
{int i;
scanf("%d",&n);
while(n--)
{scanf("%lld%lld",&a,&b);
long long p=a*b,c;
c=(long long)round(pow((double)p,(1.0)/(3.0)));
if(c==0||(c*c*c)!=p)printf("Non");
else if(a%c==0&&b%c==0)printf("Yesn");
else printf("Non");
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
long long a,b;
int n;
int main()
{int i;
scanf("%d",&n);
while(n--)
{scanf("%lld%lld",&a,&b);
long long p=a*b,c;
c=(long long)round(pow((double)p,(1.0)/(3.0)));
if(c==0||(c*c*c)!=p)printf("Non");
else if(a%c==0&&b%c==0)printf("Yesn");
else printf("Non");
}
return 0;
}
最后
以上就是细心蓝天为你收集整理的Codeforces Round #426 (Div. 2) C:The Meaningless Game The Meaningless Game的全部内容,希望文章能够帮你解决Codeforces Round #426 (Div. 2) C:The Meaningless Game The Meaningless Game所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复