我是靠谱客的博主 细心蓝天,最近开发中收集的这篇文章主要介绍Codeforces Round #426 (Div. 2) C:The Meaningless Game The Meaningless Game,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

题目:

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 ab (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).



题目大意:现在有两个人玩游戏,一开始两个人的分数都是1,每一轮游戏两个人会共同挑选一个数k,游戏获得胜利的选手将自己的分数 *k^2,输了的选手将自己的分数*k.现在有n个查询,每个查询表示两个人最终的分数,问是否有一种游戏过程,使得这个最终分数是可能出现的。

  注意:每一轮的k值并不一定相同。

思路:

  (以下所有字母均表示整数)

  对询问的两个数a、b,均可写成如下形式:
     
        a=(k1^2)(k2)(k3^2)(k4)......
    b=(k1)(k2^2)(k3)(k4^2)......

  即:
        
        a=(s^2)(p)
    b=(p^2)(s)

观察可发现如下特征:


      1.a*b=(k1k2k3...kn)^3。

    2.(k1k2k3...kn)能整除a,b。


那么可认为,符合以上特征的a、b符合题意。

证明:

  已知x= ³√(a*b),x可整除a和b,则a=(s^2)(p),b=(s)(p^2),其中s、p均为整数。

  x^3=a*b,a=k1*x,b=k2*x,解得a=(k1^2)(k2),b=(k1)(k2^2)。


代码:
#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所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部