A. The Meaningless Game
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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,和结束分值(a,b),现在判断有没有可能通过数局游戏到达这个分值。

规则,每次选出一个自然数k,其中一个人的分值乘上k*k,另一个人就乘上k,反之亦然。

当时推出来式子了,却没想到怎么证明哎。

设进行了n局游戏,则有  a*b=(k1*k2*k3......kn)3,这个并不难证明,我们假设存在整数c=k1*k2*k3....*kn使得等式成立,

则c=cbrt(a*b),接着就要找c和a,b的关系,如果c真的存在那么a,b都能整除以c,x=a/c,y=b/c;

如果x,y是正确的解那么代回去之后   a=x*x*y  b=y*y*x; 判断一下就好了。

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
int main()
{
int n;
LL a,b;
scanf("%d",&n);
while(n--){
scanf("%lld%lld",&a,&b);
LL c=cbrt((long double)a*b);
LL x=a/c,y=b/c;
if(a==x*x*y&&b==y*y*x) puts("Yes");
else puts("No");
}
return ;
}

上面是看的别人的其实这个思路不是很好懂,如果c存在的话,那么我们可以二分出c的值进行判定c*c*c==a*b是否成立即可,但注意这并不是充要条件,

c还要满足 a%c==0&&b%c==0没写这两个导致我WA

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
LL solve(LL a,LL b)
{
LL l=,r=1e6;
while(l<r){
LL mid=(l+r)>>;
LL m3=mid*mid*mid;
if(m3==a*b&&a%mid==&&b%mid==) return ;
else if (m3>a*b) r=mid-;
else l=mid+;
}
if(l==r&&l*l*l==a*b&&a%l==&&b%l==) return ;
return ;
}
int main()
{
int n;
LL a,b;
scanf("%d",&n);
while(n--){
scanf("%lld%lld",&a,&b);
if(solve(a,b)) puts("Yes");
else puts("No");
}
return ;
}

cf 833 A 数论的更多相关文章

  1. CF 833 B. The Bakery

    B. The Bakery http://codeforces.com/contest/833/problem/B 题意: 将一个长度为n的序列分成k份,每份的cost为不同的数的个数,求最大cost ...

  2. 【题解】CF#833 B-The Bakery

    一个非常明显的 \(nk\) dp 状态 \(f[i][k]\) 表示以 \(i\) 为第 \(k\) 段的最后一个元素时所能获得的最大代价.转移的时候枚举上一段的最后一个元素 \(j\)更新状态即可 ...

  3. CF 980D Perfect Groups(数论)

    CF 980D Perfect Groups(数论) 一个数组a的子序列划分仅当这样是合法的:每个划分中的任意两个数乘积是完全平方数.定义a的权值为a的最小子序列划分个数.现在给出一个数组b,问权值为 ...

  4. CF 984C Finite or not? (数论)

    CF 984C Finite or not? (数论) 给定T(T<=1e5)组数据,每组数据给出十进制表示下的整数p,q,b,求问p/q在b进制意义下是否是有限小数. 首先我们先把p/q约分一 ...

  5. cf 450b 矩阵快速幂(数论取模 一大坑点啊)

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  6. CF 371B Fox Dividing Cheese[数论]

    B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. cf(#div1 B. Dreamoon and Sets)(数论)

    B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. cf(#div1 A. Dreamoon and Sums)(数论)

    A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...

  9. cf 645F Cowslip Collections 组合数学 + 简单数论

    http://codeforces.com/contest/645/problem/F F. Cowslip Collections time limit per test 8 seconds mem ...

随机推荐

  1. labview 的连接

    https://www.youtube.com/watch?v=AsQ56CmnfEA&list=PLp02wZHiCj4tcot7tPumcOeVR51oqzf6V

  2. Yii 2.x 和1.x区别以及yii2.0安装

    知乎上有个类似的问题:http://www.zhihu.com/question/22924271/answer/23085751 大致思路不会变,开发流程变化也不是很大.有变化的是1.yii2带入的 ...

  3. @FindBy、@FindBys、@FindAll的区别

    原文地址http://blog.csdn.net/tea_wu/article/details/21080789 selenium-webdriver中获取页面元素的方式有很多,使用注解获取页面元素是 ...

  4. VirtualBox AndroidX86 网络设置

    在Virtualbox中,把虚拟机网络设为“网络地址转换(NAT)”模式,高级中控制芯片(T)选择:PCnet-FAST III(Am79C973), 然后启动你的android-x86 4.0虚拟机 ...

  5. dubbo-admin 部署

    上一章主要是谈到zookeeper的安装和部署 因为zookeeper只是一个黑框,我们无法看到是否存在了什么提供者或消费者,这时就要借助Dubbo-Admin管理平台来实时的查看,也可以通过这个平台 ...

  6. Winter-2-STL-E Andy's First Dictionary 解题报告及测试数据

    use stringstream Time Limit:3000MS     Memory Limit:0KB Description Andy, 8, has a dream - he wants ...

  7. path.resolve()和path.join()

    resolve 作用:path.resolve() 该方法将一些的 路径/路径段 解析为绝对路径. 语法:path.resolve([...paths]) 说明: ...paths <strin ...

  8. JS类、对象、方法、prototype、_proto_

    案例代码: function People(name) { //对象属性 this.name = name; //对象方法 this.Introduce = function() { alert(&q ...

  9. logstash运输器以及kibana的更多操作

    为了达到不会因为ELK中的某一项组件因为故障而导致整个ELK工作出问题,于是 将logstash收集到的数据存入到消息队列中如redis,rabbitMQ,activeMQ或者kafka,这里以red ...

  10. 先记录一下吧 开始的程序 hello!java!

    起床后就跟着老师的教学,也稍微学了一些,刚开始用java. 一堆大小写字母注意不过来,很尴尬. 虽然只是成功了一个"hello java "的简单的不能再简单的小程序,不过还是有点 ...