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 ...
随机推荐
- MySQL中不同场景中排它锁的不同表现
mysql5.7 Golang的gorm做的测试 最后结论如下: 按主键查询,只会锁查到的那条数据 按主键加其他字段查询同上, 按照非主键字段查询,查到查不到都会造成表锁 (以上的锁指排他锁) 排它锁 ...
- 位图(bitmap)原理以及实现
大家好,我是蓝胖子,我一直相信编程是一门实践性的技术,其中算法也不例外,初学者可能往往对它可望而不可及,觉得很难,学了又忘,忘其实是由于没有真正搞懂算法的应用场景,所以我准备出一个系列,囊括我们在日常 ...
- 「loj - 6179」Pyh 的求和
link. 我们想要求出 \(\varphi(ij)=\varphi(i)\varphi(j)C\) 中的常数.先研究 \(i=p^a\),\(j=p^b\) 的情况,即 \(\varphi(p^{a ...
- Learning Hard C# 学习笔记: 6.C#中的接口
目的: 由于C#中的类只能单个继承, 为了满足多重继承(一个子类可以继承多个父类)的需求, 所以产生了接口. 多重继承是指一个类可以从多个父类继承属性和方法.在C#中,只允许单继承,即一个类只能有一个 ...
- 详解RecyclerView的预布局
概述 RecyclerView 的预布局用于 Item 动画中,也叫做预测动画.其用于当 Item 项进行变化时执行的一次布局过程(如添加或删除 Item 项),使 ItemAnimator 体验更加 ...
- 炫酷转换:Java实现Excel转换为图片的方法
摘要:本文由葡萄城技术团队原创并首发.转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 前言 在实际开发过程中,经常会有这样的需求:将Excel表格或特定区域 ...
- .Net核心级的性能优化(GC篇)
1.前言 大部分人对于.Net性能优化,都停留在业务层面.或者简单的.Net框架配置层面.本篇来看下.Net核心部分GC垃圾回收配置:保留VM,大对象,独立GC,节省内存等.Net8里面有很多的各种G ...
- CF1368B
题目简化和分析: 因为要求长度最小,所以我们每个字符就应该发挥最大的价值,不会有没有作用的字符. 设有 \(x_1\) 个 \(c\) ,\(x_2\) 个 \(o\) ,\(x_3\) 个 \(d\ ...
- 虹科干货 | 打破传统!金融界黑科技—虹科Redis企业版数据库
金融行业数字化转型浪潮来袭,客户需求也正加速向在线金融服务转移.金融机构想要实现现代化改造技术堆栈,为客户提供实时交互.欺诈检测等一系列个性化创新服务,就必须重视遗留系统和传统数据库架构"老 ...
- 源码搭建zabbix平台
1.基于lnmp部署zabbix监控平台; zabbix优点: 1.支持自动发现服务器和网络设备: 2.分布式的监控体系和集中式的WEB管理: 3.支持主动监控和被动监控模式: 4.基于SNMP.IP ...