题目

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 kk 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 \(k^{2}\), and the loser's score is multiplied by kk . 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 nn 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.

Slastyona和她的忠实狗狗普什克正在玩一个毫无意义但是很有趣的游戏。游戏包括多个回合。

它的规则非常简单:先选择一个自然数\(k\)。然后,谁说(或吠)的比另一个快就会赢得一局。胜利者的得分在那之后会乘以k的平方,而输了的人的得分就只能乘以k。比赛开始时,Slastyona和PurSok都有一个初始分数。不幸的是,Slastyona丢失了记事本,那里记录了他们玩过的N个游戏的历史。她设法回忆了每一场比赛的最终结果,但是记忆都很模糊。帮助Slastyona验证它们的正确性,或者,换句话说,对于每一对给定的分数,确定游戏是否能够完成这样的结果。

输入格式

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

样例输入

6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000

样例输出

Yes
Yes
Yes
No
No
Yes

题解

设\(a\)和\(b\)是两个人比赛的得分,对于\(a\)和\(b\)来说,每轮游戏不是\(a=a \cdot k,b=b \cdot k^2\),就是\(a=a \cdot k^2,b=b \cdot k\),显然每轮游戏,\(a \cdot b\)的总和都会被乘\(k^3\),那么对 最后得分 开三次方后是整数,说明可能存在这种情况。

但是注意,这个条件并不充足。

还有一个条件,就是开立方的结果是\(a\)和\(b\)的因数

\(\because ab=k^{3n}\)

$\therefore \sqrt[3]{ab} = \sqrt[3]{k^{3n}} = k^n $

设进行了\(p\)次游戏,\(a\)或\(b\)最少乘了\(p\)次\(k\),则\(k^n\)(开立方结果)一定是\(a\)和\(b\)的因数

反过来也成立,当\(\sqrt[3]{ab}=k^n\)是整数 且 \(k^n\)是\(a\)和\(b\)的因数 时,得分是合法的

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long a, b;
scanf("%lld%lld", &a, &b);
long long m = pow(a * b, (1.0 / 3)) + 0.5;
puts((m * m * m != a * b || a % m || b % m) ? "No" : "Yes");
}
return 0;
}

CF833A The Meaningless Game 题解的更多相关文章

  1. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  2. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  3. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  4. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  5. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  6. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  7. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  9. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

随机推荐

  1. Windows下虚拟机Linux(CentOS8)扩容设置 - 磁盘扩容中的坑和解决方法

    摘要:[原创]转载请注明作者Johnthegreat和本文链接 由于虚拟机空间不足,为了避免重装虚拟机,做了一次无损扩容.   过程中的报错如下: [root@localhost ~]# pvcrea ...

  2. 6.keras-基于CNN网络的Mnist数据集分类

    keras-基于CNN网络的Mnist数据集分类 1.数据的载入和预处理 import numpy as np from keras.datasets import mnist from keras. ...

  3. iOS-AutoLayout中动画使用的细节 和 iOS layout机制

    在Main.storyboard拖入一个UIView,随便设置一个背景色, 使用autolayout  为紫色的view添加约束 :(0,0,100,100) , 为该view添加动画代码如下: #i ...

  4. 学习Redis好一阵了,我对它有了一些新的看法

    前言 本篇文章不是一篇具体的教程,我打算记录一下自己对Redis的一些思考.说来惭愧,我刚接触Redis的时候只是简单地使用了一下,背了一些面试题,就在简历上写下了Redis这个技能点. 我们能在网络 ...

  5. 如何通过AzureAD平台提供的授权方式访问sharepoint online

    官方文档: 1.https://docs.microsoft.com/zh-cn/previous-versions/azure/dn645543(v=azure.100)?redirectedfro ...

  6. Sublime Text 3.1 注册码

    加入到hosts文件: 127.0.0.1 www.sublimetext.com 127.0.0.1 license.sublimehq.com hosts 文件的位置: Windows : c:/ ...

  7. 常用sql进阶语句

    一.扩展数据库表字段长度 --mysql alter table user modify name varchar2 (32); --oracle alter table A modify(name ...

  8. http 的8中请求方式:

    http 的8中请求方式: 1.OPTIONS 返回服务器针对特定资源所支持的HTTP请求方法,也可以利用向web服务器发送‘*’的请求来测试服务器的功能性 2.HEAD 向服务器索与GET请求相一致 ...

  9. MySQL-数据库和表的基本操作

    数据库和表的基本操作 数据库基础知识 创建数据库 CREATE DATABASE 数据库名称 ; 查看数据库(显示数据库名列表) SHOW DATABASES ; 查看某数据库信息(显示创建的信息) ...

  10. 微信小程序-APP生命周期与运行机制

    QQ讨论群:785071190 开发微信小程序之前需要先了解微信小程序运行机制以及其生命周期,小程序APP生命周期需要先从app.js这个文件开始. 阅读过"微信小程序-代码构成" ...