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. gbdt调参的小结

    关键部分转自http://www.cnblogs.com/pinard/p/6143927.html 第一次知道网格搜索这个方法,不知道在工业中是不是用这种方式 1.首先从步长和迭代次数入手,选择一个 ...

  2. 关于/proc/进程idpid/fd ,根据fd来查找连接

    当创建好epoll句柄后,它就是会占用一个fd值,在linux下如果查看/proc/进程id/fd/,是能够看到这个fd的,所以在使用完epoll后,必须调用close()关闭,否则可能导致fd被耗尽 ...

  3. Winter-2-STL-G Team Queue 解题报告及测试数据

    Time Limit:3000MS     Memory Limit:0KB Description Queues and Priority Queues are data structures wh ...

  4. 裁剪TOGAF进行产品架构开发

    http://ea.zhoujingen.cn/56.html . 有人和我说“周老师,我的企业条件不适合,学习企业架构没用.” 如果等公司让我用企业架构,估计会比我自己开始晚七八年.我们学习任何内容 ...

  5. convention over configuration

    惯例优先原则:也称为约定大于配置或规约大于配置(convention over configuration),即通过约定代码结构或命名规范来减少配置数量,同样不会减少配置文件:即通过约定好默认规范来提 ...

  6. Python面试题之列表推导式

    题目要求: 生成如下列表 [[0,0,0,0,0,],[0,1,2,3,4,],[0,2,4,6,8,],[0,3,6,9,12,]] (考察列表生成式和基本逻辑推理) 方法1: list1 = [] ...

  7. 20145211《网络渗透》MS12-004漏洞渗透

    20145211<网络渗透>MS12-004漏洞渗透 一 实验原理 初步掌握平台matesploit的使用 有了初步完成渗透操作的思路 在这里我选择对的不是老师推荐的MS11_050,而是 ...

  8. (转)C#调用C函数(DLL)传递参数问题

    备忘: 1.C函数参数为字符串char*.如果是入参,对应C#中string或StringBuilder:如果是出参对应C#中StringBuider: 2.C函数参数为结构体指针,需在C#中对应定义 ...

  9. CentOS7系统安装及环境初始化

    操作系统安装:    将网卡名称设置为eth*,不使用CentOS 7默认的网卡命名规则.所以需要在安装的时候,增加内核参数.1. 光标选择“Install CentOS 7” 2. 点击Tab,打开 ...

  10. linux centos7安装phpMyAdmin详解,以及解决各种bug问题

    使用php和mysql开发网站的话,phpmyadmin和navicat是目前非常好的mysql管理工具,但是phpmyadmin最主要是免费开源,目前很多集成的开发环境都会自带phpmyadmin, ...