题目

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. (三)linux三剑客之sed

    一.sed是什么? 二.sed的工作原理? 三.sed的基本用法? 四.sed的进阶使用? 一.sed是什么? sed 就是一个非交互式流编译器: 交互式:文件缓存.人工编译.全局并行可逆 非交互式: ...

  2. akka-typed(6) - cluster:group router, cluster-load-balancing

    先谈谈akka-typed的router actor.route 分pool router, group router两类.我们先看看pool-router的使用示范: val pool = Rout ...

  3. CentOS8.1安装Docker及Docker-compose

    使用 Docker 仓库进行安装 在新主机上首次安装 Docker Engine-Community 之前,需要设置 Docker 仓库.之后,您可以从仓库安装和更新 Docker. 设置仓库 安装所 ...

  4. 修改MSSQL的端口地址_TcpPort_数据库安装工具_连载_2

    修改MSSQL的端口地址_TcpPort,可在程序中调用,从而修改TcpPort Use master Go ------------------------------ --1)在注册表中查询 Pi ...

  5. 为什么启动线程是start方法?

    为什么启动线程是start方法 十年可见春去秋来,百年可证生老病死,千年可叹王朝更替,万年可见斗转星移.   凡人如果用一天的视野,去窥探百万年的天地,是否就如同井底之蛙? 背景:启动线程是start ...

  6. C#数据结构与算法系列(十):逆波兰计算器——逆波兰表达式(后缀表达式)

    1.介绍 后缀表达式又称逆波兰表达式,与前缀表达式相似,只是运算符位于操作数之后 2.举例说明 (3+4)*5-6对应的后缀表达式就是3 4 +5 * 6 - 3.示例 输入一个逆波兰表达式(后缀表达 ...

  7. for, for in, for of, map, forEach 循环的区别:

    for, for in,  for of, map, forEach 循环的区别: for  遍历数组: //对象遍历数组 var arr = [ {Monday: '星期一', Tuesday: ' ...

  8. Java操作RockeMQ

    RocketMQ是阿里巴巴在2012年开源的分布式消息中间件,目前已经捐赠给Apache基金会,已经于2016年11月成为 Apache 孵化项目,相信RocketMQ的未来会发挥着越来越大的作用,将 ...

  9. Mac上使用brew另装ruby和gem的新玩法

    [本文版权归微信公众号"代码艺术"(ID:onblog)所有,若是转载请务必保留本段原创声明,违者必究.若是文章有不足之处,欢迎关注微信公众号私信与我进行交流!] 众所周知,Mac ...

  10. 分词搜索 sphinx+php+mysql

    sphinx3.1.1的安装与使用 下载sphinx3.1.1 wget http://sphinxsearch.com/files/sphinx-3.1.1-612d99f-linux-amd64. ...