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 ...
随机推荐
- Java基础知识陷阱(七)
本文发表于本人博客. 上次说了下HashSet和HashMap之间的关系,其中HashMap这个内部有这么一句: static final float DEFAULT_LOAD_FACTOR = 0. ...
- C# 使用 SqlBulkCopy 类批量复制数据到数据库
最近公司需要优化导入的问题,由于之前使用的方式是生成 Insert 语句插入数据库,数据量小的时候还行,但是随着发展数据量渐渐大了,之前的方法性能就跟不上了,于是发现了 SqlBulkCopy 这个类 ...
- SHUOJ Arithmetic Sequence (FFT)
链接:http://acmoj.shu.edu.cn/problem/533/ 题意:求一个序列中,有多少三元组(其中元素不重复)在任意的排列下能构成等差数列. 分析:等差数列:\(A_j-A_i=A ...
- Hadoop集群的各部分常用端口
hadoop集群的各部分一般都会使用到多个端口,有些是daemon之间进行交互之用,有些是用于RPC访问以及HTTP访问.而随着hadoop周边组件的增多,完全记不住哪个端口对应哪个应用,特收集记录如 ...
- JSON 转 对象
Json对象与Json字符串的转化.JSON字符串与Java对象的转换 一.Json对象与Json字符串的转化 1.jQuery插件支持的转换方式: $.parseJSON( jsonstr ); ...
- JVM内存结构 JVM的类加载机制
JVM内存结构: 1.java虚拟机栈:存放的是对象的引用(指针)和局部变量 2.程序计数器:每个线程都有一个程序计数器,跟踪代码运行到哪个位置了 3.堆:对象.数组 4.方法区:字节流(字节码文件) ...
- 20145231熊梓宏 《网络对抗》 实验9 Web安全基础实践
20145231熊梓宏 <网络对抗> 实验9 Web安全基础实践 基础问题回答 1.SQL注入攻击原理,如何防御? •SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面 ...
- Spring MVC工作流程图
图一 图二 Spring工作流程描述 1. 用户向服务器发送请求,请求被Spring 前端控制Servelt DispatcherServlet捕获: 2. Disp ...
- asm-3.3.1.jar详解 (转)
Java字节码操纵框架.它可以直接以二进制形式动态地生成stub类或其他代理类,或者在装载时动态地修改类.ASM提供类似于BCEL和SERP之类的工具包的功能,但是被设计得更小巧.更快速,这使它适用于 ...
- 8条规则图解JavaScript原型链继承原理
原形链是JS难点之一,而且很多书都喜欢用一大堆的文字解释给你听什么什么是原型链,就算有图配上讲解,有的图也是点到为止,很难让人不产生疑惑. 我们先来看一段程序,友情提示sublimeText看更爽: ...