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 ...
随机推荐
- codeforces600E. Lomsat gelral(dsu on tree笔记)
知识前驱:树链剖分 codeforces600E. Lomsat gelral 题意:给出一个树,求出每个节点的子树中出现次数最多的颜色的编号和 分析:递归求解,对于一棵树,求出他的所有子树的颜色编号 ...
- 弹性数据库连接池探活策略调研(一)——HikariCP
调研背景: 数据库连接建立是比较昂贵的操作(至少对于 OLTP),不仅要建立 TCP 连接外还需要进行连接鉴权操作,所以客户端通常会把数据库连接保存到连接池中进行复用.连接池维护到弹性数据库(JED) ...
- Solution Set -「ARC 109」
「ARC 109A」Hands Link. 讨论即可,除了煞笔出题人写了个死马的题面. #include<cstdio> #include<algorithm> using n ...
- Solution -「THUPC 2019」Duckchess
Description Link. 大模拟是不可能给你概括题意的. Solution (据说鸭棋题解用这个标题很吉利)(这里是被点名批评的 长度 19k 的打法)(先说好代码里 Chinglish 满 ...
- 数据库sql中处理时间冲突问题
数据库现有数据其中两列: s - 开始时间, e - 结束时间. 在新插入数据s', e'之前需要判断两个时间之间是否有重合 因为使用mybatis-plus的缘故, 结论都使用s或e在符号前面. 1 ...
- .Net7自定义GC垃圾回收器
1.前言 CLR和GC高度耦合,.Net7里面分离CLR和GC,则比较容易实现这件事情.本篇来看下,自定义一个GC垃圾回收器. 2.概述 这里首先演示下自定义GC垃圾回收后的效果. 1.下载Custo ...
- python第2~5章 code
02基本语法 print('he\aaa\aaa') # 这是一个打印语句,请你看见了不要慌张# 这是一个注释# 注释会被解释器所忽略# print(123+456) 这行代码被注释了,将不会执行pr ...
- Oracle和达梦:连接多行查询结果
Oracle和达梦:LISTAGG连接查询结果 LISTAGG介绍 使用LISTAGG函数,您可以将多行数据连接成一个字符串,并指定分隔符进行分隔.这在需要将多行数据合并为单个字符串的情况下非常有用, ...
- [NISACTF 2022]level-up
[NISACTF 2022]level-up 查看源码,根据这个提示就可以反应出是需要去访问robots.txt这个文件 访问level_2_1s_h3re.php进入第二关 需要post进去arra ...
- 【虹科干货】Redis Enterprise vs ElastiCache——如何选择缓存解决方案?
使用Redis 或 Amazon ElastiCache 来作为缓存加速已经是业界主流的解决方案,二者各有什么优势?又有哪些区别呢? 为了提高 Web 应用程序和数据驱动服务的性能与效率,使用 Red ...