HPU第七周周练 I
来源:互联网 发布:手机淘宝如何联系卖家 编辑:程序博客网 时间:2024/05/19 13:16
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.
Input
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.
Output
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).
Example
Input
62 475 458 816 16247 9941000000000 1000000OutputYesYesYesNoNoYes
Note
First 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.
题意:有一个狗和他的主人在玩游戏,有n回合,谁赢的话谁的分数就乘以k^2,输的话就乘以k,然而主人忘了他的分数,现在给你一对数,让你判断这一对数是否合法;
思路:a=k1^2(k1) * k2^2(k2) * k3^2(k3)…….kn^2(kn);
b=k1^2(k1) * k2^2(k2) * k3^2(k3)…….kn^2(kn);
a*b=(k1 * k2 * k3 * …… * kn)^3;
所以这个问题就转化为了判断是否有一个整数的三次方等于a * b;
a*b的范围为1~1e18,所以只要判断到1e6就行了,
打表+二分,复杂度 O(n);
下面附上代码:
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int MAXN=1e6+5;LL a,b;LL s[MAXN];void init(){ for(LL i=1;i<=MAXN;i++) s[i]=i*i*i;}int main(){ int n; cin>>n; init(); while(n--) { scanf("%lld %lld",&a,&b); LL sum=a*b; LL p=lower_bound(s,s+MAXN,sum)-s; //printf("%lld %lld %lld %lld\n",p,s[p],sum,s[p-1]); if(s[p]==sum&&(a*a%b==0)&&(b*b%a==0)) puts("Yes"); else puts("No"); } return 0;}
阅读全文
0 0
- HPU第七周周练 I
- HPU第七周周练 A
- 【第二周周练 H 】
- 【第二周周练 E 】
- 第七周周报
- 实验室第七周周工作总结
- 第七周周工作表
- 第七周周总结
- 第七周周总结
- 第七周周报
- 第七周周四总结
- 第七周周中总结
- 第七周周末总结
- 第七周周总结
- hpu暑期训练:I
- hpu暑假训练I
- HPU第七次测试1002
- hpuacm15级第13周周练
- HTML的checkbox多选框---按条件选择
- 图像基础19 人脸辨识——人脸识别
- java 反射机制 之 getDeclaredField 获取私有保护字段, 再setAccessible(true)取消对权限的检查 实现对私有的访问和赋值
- HDU
- Wannafly挑战赛3 A 概率DP+双指针
- HPU第七周周练 I
- 中国移动网络下网页加载资源无法正常使用问题
- windows下安装redis以及一些常规操作
- 剑指offer-栈的压入弹出序列
- 原码、补码与反码
- 色彩编码の简单介绍
- Android Study Material Design 七 之 谈谈ToolBar以及SearchView
- python数组循环处理
- str .list.touple.dict 类的某些功能