题目链接:

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 (二分+数学)的更多相关文章

  1. Codeforces Round #426 (Div. 2) C. The Meaningless Game

    C. The Meaningless Game 题意: 两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样 ...

  2. 【筛法求素数】Codeforces Round #426 (Div. 1) A. The Meaningless Game

    先筛出来1000以内的素数. 枚举x^(1/3) 和 y^(1/3)以内的素因子,这样除完以后对于x和y剩下的因子,小的那个的平方必须等于大的. 然后判断每个素因数的次数之和是否为3的倍数,并且小的那 ...

  3. Codeforces Round #127 (Div. 1) E. Thoroughly Bureaucratic Organization 二分 数学

    E. Thoroughly Bureaucratic Organization 题目连接: http://www.codeforces.com/contest/201/problem/E Descri ...

  4. Codeforces Round #275 (Div. 2) B. Friends and Presents 二分+数学

    8493833                 2014-10-31 08:41:26     njczy2010     B - Friends and Presents             G ...

  5. CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)

    /* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...

  6. Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点

    // Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...

  7. 【Codeforces Round #426 (Div. 2) C】The Meaningless Game

    [Link]:http://codeforces.com/contest/834/problem/C [Description] 有一个两人游戏游戏; 游戏包括多轮,每一轮都有一个数字k,赢的人把自己 ...

  8. 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 ...

  9. Codeforces Round #426 (Div. 2)

    http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...

随机推荐

  1. scp---远程拷贝文件

    scp命令用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的.可能会稍微影响一下速度.当你服务器硬盘变为只读read onl ...

  2. 【Uva 1601】The Morning after Halloween

    [Link]: [Description] 给你一张平面图; 最多可能有3只鬼; 给出这几只鬼的初始位置; 然后,这几只鬼有各自的终点; 每秒钟,这几只鬼能同时移动到相邻的4个格子中的一个 任意两只鬼 ...

  3. hdu1078 FatMouse and Cheese(记忆化搜索)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1078" target="_blank">http://acm. ...

  4. jQuery对表格进行类样式

    <%-- <%@ page language="java" contentType="text/html; charset=utf-8" pageE ...

  5. Linq复杂对象查询

    复杂的查询对象, using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...

  6. [ Java ] [ Spring ] Spring 一些配置项 及 <context:annotation-config/> 專文解释说明

    節錄重點: @ Resource .@ PostConstruct.@ PreDestro.@PersistenceContext.@Required 都必須聲明相關的 bean 所以如果總是需要按照 ...

  7. Codefroces B. New Skateboard

    B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. Linux-swap分区

    Linux内核为了提高读写效率与速度,会将文件在内存中进行缓存,这部分内存就是Cache Memory(缓存内存).即使你的程序运行结束后, Cache Memory也不会自动释放.这就会导致你在Li ...

  9. Linux下关机命令的区别 (halt,poweroff,reboot,shutdown,init)

    1.shutdown shutdown命令安全地将系统关机.    而在系统关机前使用shutdown命令﹐系统管理员会通知所有登录的用户系统将要关闭.并且login指令会被冻结﹐即新的用户不能再登录 ...

  10. 引用 Windows Server 2003 FTP服务器配置详解

    引用 昆神之星 的 Windows Server 2003 FTP服务器配置详解 1.FTP文件传输协议,主要用于计算机之间文件传输,是互联网上仅次于www的第二大服务.本文主要演示如何在Window ...