CF833A The Meaningless Game 题解
题目

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 题解的更多相关文章
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 网络流n题 题解
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...
随机推荐
- MySQL进阶篇(02):索引体系划分,B-Tree结构说明
本文源码:GitHub·点这里 || GitEE·点这里 一.索引简介 1.基本概念 首先要明确索引是什么:索引是一种数据结构,数据结构是计算机存储.组织数据的方式,是指相互之间存在一种或多种特定关系 ...
- 将XML转换为JSON并强制数组
string xml = @"<person id='1'> <name>Alan</name> <url>http://www.google ...
- Python字符串处理 - str/bytes
目录 1. str 2. bytes / bytearray 3. printf-style String Formatting 1. str homepage str.count(sub[, sta ...
- TensorFlow从0到1之浅谈感知机与神经网络(18)
最近十年以来,神经网络一直处于机器学习研究和应用的前沿.深度神经网络(DNN).迁移学习以及计算高效的图形处理器(GPU)的普及使得图像识别.语音识别甚至文本生成领域取得了重大进展. 神经网络受人类大 ...
- LR脚本信息函数-lr_user_data_point
Loadrunner中lr_user_data_point.lr_user_data_point_instance两个函数可以用来记录一条自定义的Vuser运行数据,并将其输出到测试结果中,最后可以通 ...
- C#构造函数 -0028
默认构造函数 声明基本构造函数的语法就是声明一个与类同名的方法,但该方法没有返回类型: public class MyClass { public MyClass() { } // rest of c ...
- 学员操作——制作5s关闭广告
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>广 ...
- CODING DevOps 系列第四课:DevOps 中的质量内建实践
什么是质量内建 随着时间的推移,我们项目的开发效率会逐渐降低,直到几年之后整个项目可能就无法维护,只能推倒重来.具体的表现首先就是随着时间推移,我们会发现整个需求列表里面能做的需求越来越少,因为每当我 ...
- Andrew Ng - 深度学习工程师 - Part 1. 神经网络和深度学习(Week 3. 浅层神经网络)
=================第3周 浅层神经网络=============== ===3..1 神经网络概览=== ===3.2 神经网络表示=== ===3.3 计算神经网络的输出== ...
- 我们是如何做go语言系统测试覆盖率收集的?
工程效能领域,测试覆盖率度量总是绕不开的话题,我们也不例外.在七牛云,我们主要使用go语言构建云服务,在考虑系统测试覆盖率时,最早也是通过围绕原生go test -c -cover的能力来构建.这个方 ...