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 ...
随机推荐
- Linux服务器---apache支持cgi
Apache支持cgi 1.打开Apache配置文件httpd.conf,搜索“cgi”,找到下面的一段,去掉“addhandler”前面的“#“,这样就开启了Apache的cgi功能 [root@ ...
- python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法
python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法 在Python中字符串处理函数里有三个去空格(包括'\n', '\r', '\t', ' ')的函数 ...
- SNMP学习笔记之SNMPv3的报文格式以及基于USM的认证和加密过程
下面我们就主要讲解SNMPv3的报文格式以及基于USM的认证和加密过程! 1.SNMPv3的消息格式 如下图1: 图 1 其中,整个SNMPv3消息可以使用认证机制,并对EngineID.Contex ...
- C++设计模式(第一周)
part 1 设计模式简介 课程目标 1.理解松耦合设计思想 2.掌握面向对象设计原则 3.掌握重构技法改善设计 4.掌握GOF 核心设计模式 什么是设计模式? “每一个模式描述了一个在我们周围不断重 ...
- 20145309李昊《网络对抗技术》实验9 web安全基础实践
本实验在同学帮助下完成 一.实验准备 1.0 实验目标和内容 Web前端HTML.能正常安装.启停Apache.理解HTML,理解表单,理解GET与POST方法,编写一个含有表单的HTML. Web前 ...
- 探索Java8:(三)Predicate接口的使用
上一篇学习了下Function接口的使用,本篇我们学习下另一个实用的函数式接口Predicate. Predicate的源码跟Function的很像,我们可以对比这两个来分析下.直接上Predicat ...
- Win10 Edge浏览器怎么重装 Win10重装Edge浏览器
具体如下: 重新安装Microsoft Edge 1.按Windows键+ R,打开 输入以下代码,可以直接复制黏贴. %LocalAppData%\Packages\Microsoft.Micros ...
- 如何Python写一个安卓APP
前言:用Python写安卓APP肯定不是最好的选择,但是肯定是一个很偷懒的选择,而且实在不想学习Java,再者,就编程而言已经会的就Python与Golang(注:Python,Golang水平都一般 ...
- 区间内x的出现个数(主席树)
题目大概:求区间内x出现的次数 出题人yjy Description ZJK 给你一个长度为 n 的数列和 m 次询问,每次询问从第 l 个到第 r 个数中,数 x 出现了多少次.Input第一行一个 ...
- Centos7.2 修改网卡名称
查看ip [root@localhost network-scripts]# ip addr : lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue ...