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

来源:互联网 发布:陈田拆车件有淘宝店吗 编辑:程序博客网 时间:2024/06/07 11:25

题目:

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("No\n");   else if(a%c==0&&b%c==0)printf("Yes\n");  else printf("No\n"); } return 0;}






阅读全文
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 头顶的头发越来越少怎么办 四岁宝宝头发稀少怎么办 一岁宝宝头发稀少怎么办 三岁宝宝头发稀少怎么办 头发油急着出门怎么办 长出的头发毛糙弯曲怎么办 头发薄还掉头发怎么办 头发少掉的厉害怎么办 一洗头就掉很多头发怎么办 生完孩子掉头发怎么办 甲减引起的肥胖怎么办 18岁掉头发严重怎么办 5岁儿童掉头发严重怎么办 18头发掉的严重怎么办 甲癌碘131后腮腺肿大怎么办 头发出油发丝细怎么办 25岁总掉头发怎么办 25岁掉头发厉害怎么办 我25岁经常掉头发怎么办 25岁掉头发很厉害怎么办 我今年25岁掉头发怎么办 头顶头发稀少怎么办有方法吗 头发又干又黄怎么办 2岁宝宝头发细软怎么办 头发突然变得稀疏了怎么办 孕期掉头发很厉害怎么办 冬天头发掉的厉害怎么办 怀孕期间掉头发比较严重怎么办 头发油腻容易掉发怎么办 最近头发掉的厉害怎么办 头发新长的绒毛怎么办 久躺床上头发黏在一起怎么办 头发长油怎么办小妙招 头发出油多脱发怎么办 头发出油掉头发怎么办 在英国狂掉头发怎么办 我头发油头皮痒脱发怎么办 油性头发容易掉发怎么办 洗了头发很蓬松怎么办 小孩头皮黄掉头发怎么办 头发又油又掉发怎么办