题目

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. 美女面试官问我Python如何优雅的创建临时文件,我的回答....

    [摘要] 本故事纯属虚构,如有巧合,他们故事里的美女面试官也肯定没有我的美,请自行脑补... 小P像多数Python自学者一样,苦心钻研小半年,一朝出师投简历. 这不,一家招聘初级Python开发工程 ...

  2. 传递函数-微分方程-差分方程-Matlab阶跃响应曲线

    Transfer function: 1 ------- 5 s + 1 写成微分方程: 5y'(t)+y(t)=u(t) 向前差分: 5y(k+1)+(T-5)y(k)=Tu(k) T:Sample ...

  3. Linux 安装 MySql5.7

    首先在官网下载对应版本的Linux安装包.一般来说应用 community 版本就可以. mysql community version download addr 1. 将文件上传至 Linux 并 ...

  4. YAML语法:

    1.基本语法 k:(空格)v:表示一对键值对(空格必须有): 以空格的缩进来控制层级关系:只要是左对齐的一列数据,都是同一个层级的 server: port: 8081 path: /hello 属性 ...

  5. Remap 后的 USART1 不能发送数据

    最近在使用 STM32 的 USART1 时,遇到一点问题,记录一下. 如果 USART1 不是使用 PA9 和 PA10 作接收和发送引脚,而是 PB6 和 PB7,那么有一点就一定得注意了:此时 ...

  6. @atcoder - AGC024F@ Simple Subsequence Problem

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定由若干长度 <= N 的 01 字符串组成的集合 S. ...

  7. 私有云nextcloud、seafile、syncthing的比较

    可选 nextcloud.seafile.syncthing 1. seafile https://www.jianshu.com/p/43f570118e63 https://www.jianshu ...

  8. 使用torch实现RNN

    (本文对https://blog.csdn.net/out_of_memory_error/article/details/81456501的结果进行了复现.) 在实验室的项目遇到了困难,弄不明白LS ...

  9. webpack介绍—上

    6.1 webpack概念的引入 在网页中会引用哪些常见的静态资源? JS .js. .jsx ..coffee. .ts(TypeScript 类 C# 语言) CSS .css. .less. . ...

  10. CSS sprites的定义及使用

    定义:CSS sprites 其实就是把网页中的一些背景图片整合到一张图片文件中,再利用CSS的“background-image”.“background-repeat”.“background-p ...