Codeforces 834C - The Meaningless Game
数学。
思路1:判断a•b能不能化成v3且a%v==0且b%v==0。v可以直接用pow求(或者用cbrt),也可以二分求;还可以用map映射预处理,使得所有的map[v*v*v]=v。
代码1(cbrt版,296 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ls rt<<1,l,m
#define rs rt<<1|1,m+1,r
#define pb push_back
const int INF=0x3f3f3f3f;
const int N=1e6+;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
map<ll,ll>mp;
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
ll a,b;
scanf("%lld %lld",&a,&b);
ll m=a*b;
ll v=cbrt((ld)m);
ll x=a/v,y=b/v;//a*b==x*y*v*v==v*v*v得出v=x*y
if(x*x*y==a&&x*y*y==b)puts("Yes");
else puts("No");
}
return ;
}
代码2(pow版,311 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ls rt<<1,l,m
#define rs rt<<1|1,m+1,r
#define pb push_back
const int INF=0x3f3f3f3f;
const int N=1e5+;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
ll a,b;
scanf("%lld %lld",&a,&b);
ll m=a*b;
ll v=pow(m,./);
while(v*v*v<m)v++;
if(v*v*v!=m||a%v!=||b%v!=)puts("No");
else puts("Yes");
}
return ;
}
代码3(二分版,327 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ls rt<<1,l,m
#define rs rt<<1|1,m+1,r
#define pb push_back
const int INF=0x3f3f3f3f;
const int N=1e6+;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
ll a,b;
scanf("%lld %lld",&a,&b);
ll m=a*b;
int l=,r=N;
ll mid;
while(l<r)
{
mid=(l+r)>>;
if(mid*mid*mid<a*b)l=mid+;
else r=mid;
}
ll v=mid;
while(v*v*v<m)v++;
if(v*v*v!=m||a%v!=||b%v!=)puts("No");
else puts("Yes");
}
return ;
}
代码4(map版,717 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ls rt<<1,l,m
#define rs rt<<1|1,m+1,r
#define pb push_back
const int INF=0x3f3f3f3f;
const int N=1e6+;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
map<ll,ll>mp;
int main()
{
int n;
for(ll i=;i<N;i++)mp[i*i*i]=i;
scanf("%d",&n);
while(n--)
{
ll a,b;
scanf("%lld %lld",&a,&b);
ll m=a*b;
if(!mp[m])puts("No");
else
{
if(a%mp[m]||b%mp[m])puts("No");
else puts("Yes");
}
}
return ;
}
思路2:gcd(a,b)=∏kiaki(1≤aki≤2),a•b=∏ki3。先看a•b能不能化成v3,如果不能输出No;否则,因为c=gcd(gcd(a,b),a•b)肯定包含了∏ki,所以a•b除以3次c后不能变成1,那么输出No,否则,输出Yes。
代码5(389 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ls rt<<1,l,m
#define rs rt<<1|1,m+1,r
#define pb push_back
const int INF=0x3f3f3f3f;
const int N=1e5+;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
ll a,b;
scanf("%lld %lld",&a,&b);
ll m=a*b;
ll v=pow(m,./);
while(v*v*v<m)v++;
if(v*v*v!=m)
{
printf("No\n");
}
else
{
ll g=gcd(a,b);
for(int i=;i<;i++)
{
ll c=gcd(g,m);
m/=c;
}
if(m!=)printf("No\n");
else printf("Yes\n");
}
}
return ;
}
Codeforces 834C - The Meaningless Game的更多相关文章
- CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)
/* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...
- Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. T ...
- Codeforces Round #426 (Div. 2) C. The Meaningless Game
C. The Meaningless Game 题意: 两个人刚刚开始游戏的时候的分数, 都是一分, 然后随机一个人的分数扩大k倍,另一个扩大k的平方倍, 问给你一组最后得分,问能不能通过游戏得到这样 ...
- Codeforces Round #426 The Meaningless Game
题目网址:http://codeforces.com/contest/834/problem/C 题目: C. The Meaningless Game Slastyona and her loyal ...
- C. Meaningless Operations Codeforces Global Round 1 异或与运算,思维题
C. Meaningless Operations time limit per test 1 second memory limit per test 256 megabytes input sta ...
- 【Codeforces Round #426 (Div. 2) C】The Meaningless Game
[Link]:http://codeforces.com/contest/834/problem/C [Description] 有一个两人游戏游戏; 游戏包括多轮,每一轮都有一个数字k,赢的人把自己 ...
- Codeforces Round #426 (Div. 1) A.The Meaningless Game (二分+数学)
题目链接: http://codeforces.com/problemset/problem/833/A 题意: 给你 \(a\) 和 \(b\),两个人初始化为 \(1\).两个人其中一方乘以 \( ...
- 【筛法求素数】Codeforces Round #426 (Div. 1) A. The Meaningless Game
先筛出来1000以内的素数. 枚举x^(1/3) 和 y^(1/3)以内的素因子,这样除完以后对于x和y剩下的因子,小的那个的平方必须等于大的. 然后判断每个素因数的次数之和是否为3的倍数,并且小的那 ...
- 【Codeforces Global Round 1 C】Meaningless Operations
[链接] 我是链接,点我呀:) [题意] 给你一个a 让你从1..a-1的范围中选择一个b 使得gcd(a^b,a&b)的值最大 [题解] 显然如果a的二进制中有0的话. 那么我们就让选择的b ...
随机推荐
- 019-centos的yum用法
1.检测系统是否已经安装过mysql或其依赖:# yum list installed | grep mysql(当然也可以用 rpm -qa | grep mysql) 2.卸载已经存在的mysql ...
- Yosemite安装libv8和therubyracer
yosemite ruby version升级的时候,会碰到类似 Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before b ...
- leetcode_目录
3Sum Closest 3Sum 4Sum Add Binary Add Two Numbers Anagrams Balanced Binary Tree Best Time to Buy and ...
- Window下PHP三种运行方式图文详解,window下的php是不是单进程的?
Window下PHP三种运行方式图文详解,window下的php是不是单进程的? PHP运行目前为止主要有三种方式: a.以模块加载的方式运行,初学者可能不容易理解,其实就是将PHP集成到Apache ...
- javaScript的内置对象以及一些常用的方法
前几天,我们学习了JavaScript的入门课程,但是要想做网站,仅仅学会入门是不够的,今后的几天,我将带领大家精通JavaScript,希望大家好好学习! JS内置对象 String对象:字符串对象 ...
- CSS3实现8种Loading效果【二】
CSS3实现8种Loading效果[二] 今晚吃完饭回宿舍又捣鼓了另外几种Loading效果,老规矩,直接“上菜“…… 注:gif图片动画有些卡顿,非实际效果! 第一种效果: 代码如下: < ...
- 华为C/C++笔试题&答案
1.static有什么用途?(请至少说明两种) 1)在函数体,一个被声明为静态的变量在这一函数被调用过程中维持其值不变. 2) 在模块内(但在函数体外),一个被声明为静态的变量可以被模块内所用函数访问 ...
- P2P原理及UDP穿透简单说明
转:http://http://andylin02.iteye.com/blog/444666 P2P原理及UDP穿透简单说明 本文章出自cnntec.com的AZ猫著,如需要转发,请注明来自cnnt ...
- python构造栈结构
栈:是一种先进后出的数据结构:本片文章,我们用python的面向对象来构造这样的数据结构. 栈中的每一个数据除了存储当前的数值外,还存储着当前数值下一个数据的类型(注意不是下一个数据的数值). cla ...
- ubuntu 更改python3为默认版本
ubuntu 自带两个python版本,一个是python2一个是python3 默认版本是python2的,想要更改ubuntu python3 为默认版本, 只需要两行命令: sudo updat ...