Codeforces Round #426 (Div. 1) A.The Meaningless Game (二分+数学)
题目链接:
http://codeforces.com/problemset/problem/833/A
题意:
给你 \(a\) 和 \(b\),两个人初始化为 \(1\)。两个人其中一方乘以 \(k^2\),另一方就乘以 \(k\)。问你能不能达到 \((a,b)\) 这个最终状态。
题解:
设 \(X\), \(P\) 表示两个乘积的集合。
那么,显然:
\(S^{2}*P=a\) ------ 1
\(S*P^{2}=b\) ------ 2
所以:\(a*b = S^{3}*P^3\)。
那么,\(S*P= ^{\sqrt[3]{ab}}\)
假设 \(S*P = x\).
又由公式 \(1,2\) 得:
\(S = \frac{a}{x}\)
\(P = \frac{b}{x}\)
所以,我们只需要检查 \(a*b\) 是否能完美开立方,以及 \(a,b\) 能否同时整除 \(x\)。前者直接二分就可以了。
\(cin\)会 TLE.....
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
const int mod = 1e9+7;
const ll INF =2e15;
ll cubic_root(ll x)
{
ll mid = 0;
ll low = 0 ,high = 1000100;
while(low <= high) {
mid = (low + high) >> 1;
if(mid * mid * mid > x) {
high = mid - 1;
}
else if(mid * mid * mid < x){
low = mid + 1;
}
else {
break;
}
}
return mid;
}
int main(int argc, char const *argv[]) {
int n;
//std::cin >> n;
scanf("%d", &n);
for(int i= 0;i < n; i++) {
ll a,b;
scanf("%lld%lld",&a,&b);
//std::cin >> a >> b;
ll x = cubic_root(a * b);
if(x * x * x != a * b) {
std::cout << "No" << '\n';
}
else if(a % x ==0 && b % x == 0) {
std::cout << "Yes" << '\n';
}
else std::cout << "No" << '\n';
}
return 0;
}
Codeforces Round #426 (Div. 1) A.The Meaningless Game (二分+数学)的更多相关文章
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
C. The Meaningless Game 题意: 两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样 ...
- 【筛法求素数】Codeforces Round #426 (Div. 1) A. The Meaningless Game
先筛出来1000以内的素数. 枚举x^(1/3) 和 y^(1/3)以内的素因子,这样除完以后对于x和y剩下的因子,小的那个的平方必须等于大的. 然后判断每个素因数的次数之和是否为3的倍数,并且小的那 ...
- Codeforces Round #127 (Div. 1) E. Thoroughly Bureaucratic Organization 二分 数学
E. Thoroughly Bureaucratic Organization 题目连接: http://www.codeforces.com/contest/201/problem/E Descri ...
- Codeforces Round #275 (Div. 2) B. Friends and Presents 二分+数学
8493833 2014-10-31 08:41:26 njczy2010 B - Friends and Presents G ...
- CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)
/* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...
- Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...
- 【Codeforces Round #426 (Div. 2) C】The Meaningless Game
[Link]:http://codeforces.com/contest/834/problem/C [Description] 有一个两人游戏游戏; 游戏包括多轮,每一轮都有一个数字k,赢的人把自己 ...
- 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 #426 (Div. 2)
http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...
随机推荐
- 【APP测试】APP弱网环境测试
方法一:利用抓包工具 1.利用fiddler通过代理连接上手机之后,进入Fiddler->Rules->Customize Rules,点击弹出的CustomRules.js文件,找到m_ ...
- 处理SpringMVC的时间错误:Field error in object 'sysDatumedetai' on field 'storagetime': rejected value [2017-11-27];
错误: 十一月 27, 2017 8:26:11 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service ...
- leetCode 85.Maximal Rectangle (最大矩阵) 解题思路和方法
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...
- 【LeetCode-面试算法经典-Java实现】【121-Best Time to Buy and Sell Stock(最佳买卖股票的时间)】
[121-Best Time to Buy and Sell Stock(最佳买卖股票的时间)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Say you have ...
- idle-实现清屏
最近在学习python的时候,需要用到ubuntu的python idle.这个工具可以测试python语法.但是呢,在使用的过程中遇到了一个问题.就是随着你的输入,你会发现这个输入会停留在这个界面的 ...
- SQL Server字符串分割函数
- 6.Maven之(六)setting.xml配置文件详解
转自:https://blog.csdn.net/u012152619/article/details/51485152
- CentOS6.5下的Nagios安装配置详解(图文)
最近因为,科研需要,接触上了Nagios,这里,我将安装笔记做个详解.为自己后续需要和博友们学习! VMware workstation 11 的下载 VMWare Workstation 11的安装 ...
- centos6.5下 python3.6安装、python3.6虚拟环境
https://www.cnblogs.com/paladinzxl/p/6919049.html # python3.6的安装 wget https://www.python.org/ftp/pyt ...
- python学习日记-180823
列表 a=[ ] 1.负数下标:a=[-1]指的是列表a最后一个下标,-2指倒数第二个下标 2.切片——利用切片获得子列表 a[1:4]——'1'切片开始处的下标,‘4’切片结束处的下标(不包括此下标 ...