cf 833 A 数论
1 second
256 megabytes
standard input
standard 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.
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
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.
题意,给出两个人的初始分值都是1,和结束分值(a,b),现在判断有没有可能通过数局游戏到达这个分值。
规则,每次选出一个自然数k,其中一个人的分值乘上k*k,另一个人就乘上k,反之亦然。
当时推出来式子了,却没想到怎么证明哎。
设进行了n局游戏,则有 a*b=(k1*k2*k3......kn)3,这个并不难证明,我们假设存在整数c=k1*k2*k3....*kn使得等式成立,
则c=cbrt(a*b),接着就要找c和a,b的关系,如果c真的存在那么a,b都能整除以c,x=a/c,y=b/c;
如果x,y是正确的解那么代回去之后 a=x*x*y b=y*y*x; 判断一下就好了。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main()
{
int n;
LL a,b;
scanf("%d",&n);
while(n--){
scanf("%lld%lld",&a,&b);
LL c=cbrt((long double)a*b);
LL x=a/c,y=b/c;
if(a==x*x*y&&b==y*y*x) puts("Yes");
else puts("No");
}
return ;
}
上面是看的别人的其实这个思路不是很好懂,如果c存在的话,那么我们可以二分出c的值进行判定c*c*c==a*b是否成立即可,但注意这并不是充要条件,
c还要满足 a%c==0&&b%c==0没写这两个导致我WA
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL solve(LL a,LL b)
{
LL l=,r=1e6;
while(l<r){
LL mid=(l+r)>>;
LL m3=mid*mid*mid;
if(m3==a*b&&a%mid==&&b%mid==) return ;
else if (m3>a*b) r=mid-;
else l=mid+;
}
if(l==r&&l*l*l==a*b&&a%l==&&b%l==) return ;
return ;
}
int main()
{
int n;
LL a,b;
scanf("%d",&n);
while(n--){
scanf("%lld%lld",&a,&b);
if(solve(a,b)) puts("Yes");
else puts("No");
}
return ;
}
cf 833 A 数论的更多相关文章
- CF 833 B. The Bakery
B. The Bakery http://codeforces.com/contest/833/problem/B 题意: 将一个长度为n的序列分成k份,每份的cost为不同的数的个数,求最大cost ...
- 【题解】CF#833 B-The Bakery
一个非常明显的 \(nk\) dp 状态 \(f[i][k]\) 表示以 \(i\) 为第 \(k\) 段的最后一个元素时所能获得的最大代价.转移的时候枚举上一段的最后一个元素 \(j\)更新状态即可 ...
- CF 980D Perfect Groups(数论)
CF 980D Perfect Groups(数论) 一个数组a的子序列划分仅当这样是合法的:每个划分中的任意两个数乘积是完全平方数.定义a的权值为a的最小子序列划分个数.现在给出一个数组b,问权值为 ...
- CF 984C Finite or not? (数论)
CF 984C Finite or not? (数论) 给定T(T<=1e5)组数据,每组数据给出十进制表示下的整数p,q,b,求问p/q在b进制意义下是否是有限小数. 首先我们先把p/q约分一 ...
- cf 450b 矩阵快速幂(数论取模 一大坑点啊)
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
- CF 371B Fox Dividing Cheese[数论]
B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...
- cf(#div1 B. Dreamoon and Sets)(数论)
B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...
- cf(#div1 A. Dreamoon and Sums)(数论)
A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...
- cf 645F Cowslip Collections 组合数学 + 简单数论
http://codeforces.com/contest/645/problem/F F. Cowslip Collections time limit per test 8 seconds mem ...
随机推荐
- Spark SQL慕课网日志分析(1)--系列软件(单机)安装配置使用
来源: 慕课网 Spark SQL慕课网日志分析_大数据实战 目标: spark系列软件的伪分布式的安装.配置.编译 spark的使用 系统: mac 10.13.3 /ubuntu 16.06,两个 ...
- javascript与jQuery的each,map回调函数参数顺序问题
<script> var arr = [2,3,6,7,9]; //javascript中的forEach 和 map方法 arr.forEach(function(value,index ...
- 2017 Multi-University Training Contest - Team 3 hdu6060 RXD and dividing
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6060 题目: RXD and dividing Time Limit: 6000/3000 M ...
- error LNK2038: 检测到“_MSC_VER”的不匹配项: 值“1600”不匹配值“1700”
原因:由于你使用了vs2012,相比较vs2010以及之前的vs为更高版本,致使msvc不兼容! 方法:在项目右键属性-配置属性-常规中,平台工具集选用为合适平台即可,我这里就选择 vs2010 (v ...
- 滑块控件CCControlSlider
#include "cocos-ext.h" //包含头文件 using namespace cocos2d::extension;//引用命名空间 /** * 创建CCContr ...
- ServletConfig获取Servlet的公共参数方法
web.xml配置: <servlet> <servlet-name>AServlet</servlet-name> <servlet-class>AS ...
- getAttribute() 与 attr() 的区别
getAttribute() 和 attr() 都是获取元素属性的方法,只是一种是 JS 写法,一种是 JQ 写法,但其实它们是有区别的. 主要区别 调用 getAttribute() 的主体必须是元 ...
- 20145335郝昊《Java程序设计》课程总结
20145335郝昊<Java程序设计>课程总结 1.读书笔记汇总 第一周学习总结:http://www.cnblogs.com/20145335hh/p/5244638.html 第二周 ...
- Spring事务管理之几种方式实现事务
1.事务认识 大家所了解的事务Transaction,它是一些列严密操作动作,要么都操作完成,要么都回滚撤销.Spring事务管理基于底层数据库本身的事务处理机制.数据库事务的基础,是掌握Spring ...
- zookeeper项目使用几点小结
背景 前段时间学习了zookeeper后,在新的项目中刚好派上了用场,我在项目中主要负责分布式任务调度模块的开发,对我自己来说是个不小的挑战. 分布式的任务调度,技术上我们选择了zookeeper,具 ...