Codeforces Round #426 (Div. 2) problem C
C. The Meaningless Gametime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputIn 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.
OutputFor 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).
Exampleinput6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000outputYes
Yes
Yes
No
No
YesNoteFirst 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.
解题思路:如果a*b==i^3 && a*a%b==0 && b*b%a==0
那么就输出Yes。否则输出No。
ps:这题其实直接用pow就可以解出了,注意精度,但是在处理高精度的方面我比较方。。。所以用二分查找。
也tle几次,发现竟然是习惯性的多查找几个数就超时了。改了之后AC了,但是时间是998ms。。。看了别人的代码都差不多,不造为什么,算了,下次还是用高精度吧。
AC代码:
1 #include<iostream>
2 #include<stdio.h>
3 using namespace std;
4 int main()
5 {
6 int T;
7 cin>>T;
8 while(T--){
9 long long a,b;
10 scanf("%lld%lld",&a,&b);
11 long long m=a*b;
12 long long l=1,r=1000000,mid=(l+r)/2;
13 bool flag=false;
14 if(a*a%b==0&&b*b%a==0){
15 while(l<=r){
16 mid=(l+r)/2;
17 if((mid*mid*mid)==m){
18 flag=true;
19 break;
20 }
21 else if((mid*mid*mid)>m){
22 r=mid-1;
23 }else{
24 l=mid+1;
25 }
26 }
27 }
28 if(flag) cout<<"Yes"<<endl;
29 else cout<<"No"<<endl;
30 }
31 return 0;
32 }
Codeforces Round #426 (Div. 2) problem C的更多相关文章
- CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)
/* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...
- Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维
& -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #753 (Div. 3), problem: (D) Blue-Red Permutation
还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com) 传送门 Problem - D - Codeforces 题意 n个数字,n ...
- Codeforces Round #426 (Div. 2)
http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...
- Codeforces Round #426 (Div. 2) A,B,C
A. The Useless Toy 题目链接:http://codeforces.com/contest/834/problem/A 思路: 水题 实现代码: #include<bits/st ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...
- Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...
随机推荐
- elasticsearch wildcard 慢查询原因分析(深入到源码!!!)
大家好,我是蓝胖子,前段时间线上elasticsearch集群遇到多次wildcard产生的性能问题, elasticsearch wildcard 一直是容易引发elasticsearch 容易宕机 ...
- PHP对关联数组(键值对数组)遍历循环
PHP对关联数组循环遍历 $arr=array('yxb'=>20,'ylg'=>21,'lgj'=18); foreach($arr as $name=>$value) { ech ...
- VOLTE:MIUI14无5G信号、通话质量差、短信收不到的原因之一
在最近一次miui版本更新后的一段时间里,先后出现以下一些情况: 1. 在"双卡与移动网络"设置中,无论如何折腾"5G网络"开关或者"5G网络模式选择 ...
- JDK8升级JDK11最全实践干货来了
1.前言 截至目前(2023年),Java8发布至今已有9年,2018年9月25日,Oracle发布了Java11,这是Java8之后的首个LTS版本.那么从JDK8到JDK11,到底带来了哪些特性呢 ...
- Teamcenter RAC 开发之《Excel模版导出》
背景 在做 Teamcenter RAC客制化表单后,TMD肯定有一个需求要导出表单,毕竟所谓的客制化表单就是从纸质表单中出来的,那么写代码必不可少......... 那么问题来了,对于一个Excel ...
- jquery设置图片可手动拖拽
JQuery是一款流行的JavaScript框架,可以轻松实现网页交互效果.而其中一种常见效果是图片手动拖拽.以下是设置图片手动拖拽的JQuery代码. 1 2 3 4 5 6 7 8 9 10 11 ...
- 高效数据传输:Java通过绑定快速将数据导出至Excel
摘要:本文由葡萄城技术团队于博客园原创并首发.转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 前言 把数据导出至 Excel 是很常见的需求,而数据的持久化 ...
- openssl加解密实战
一.概念 1.加密有两种类型 密钥加密(secret-key encryption)使用相同的密钥进行加密和解密,也叫对称加密 公钥加密(public-key encryption)使用不同的密钥进行 ...
- P6066 [USACO05JAN] Watchcow S
prologue 这个题这么水的一个板子题. analysis 这个题目我们正反建两条边,在跑欧拉回路的时候,看这个边是不是被走过,走过就不走,跳过这个边.如果没走,就走这条边并且标记这个边走过了. ...
- nittest单元测试框架—加载测试用例的3种方法以及测试报告存储管理
项目结构 测试用例 import unittest class LoginTestCase(unittest.TestCase): def test_login_success(self): self ...