题干

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 kk 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 k^2 , 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 nn 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 nn (1<=n<=350000)(1<=n<=350000) is given.

Each game is represented by a pair of scores aa , bb (1<=a,b<=10^{9})(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).

翻译

Slastyona和她的忠实狗狗普什克正在玩一个毫无意义但是很有趣的游戏。游戏包括多个回合。

它的规则非常简单:先选择一个自然数k。然后,谁说(或吠)的比另一个快就会赢得一局。胜利者的得分在那之后会乘以k的平方,而输了的人的得分就只能乘以k。比赛开始时,Slastyona和PurSok都有一个初始分数。不幸的是,Slastyona丢失了记事本,那里记录了他们玩过的N个游戏的历史。她设法回忆了每一场比赛的最终结果,但是记忆都很模糊。帮助Slastyona验证它们的正确性,或者,换句话说,对于每一对给定的分数,确定游戏是否能够完成这样的结果。

样例

​ 输入:

6
2 4
75 45
8 8
16 16
247 994
1000000000 1000000

​ 输出:

Yes
Yes
Yes
No
No
Yes

Tips

First game might have been consisted of one round, in which the number 22 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 55 , and in the second one, Pushok would have barked the number 33 .

瞎掰掰 ≧ ﹏ ≦

首先,这是一道很简单的思维题(然而最近脑子煞笔了的我依然卡了半天...),所以不要被不知所云的题干给吓唬到。

我们把花里胡哨的题干给去掉,真正的问题其实就是让我们判断每一组数据的合法性吧。这题的要点(其实也算不上难想,可我这个傻缺就是没看出来QwQ)就是我们不能分别考虑两个数,我们要把两个数之间的合法关系规律给找出来,也就是我们把两个数合起来...

初始分数是未知的,也就是任意的。改变一共有两种,乘k或者乘k^2, 问题是我们对于每轮谁乘k,谁乘k^2 ,并不清楚。而这时我们应该能反应过来,虽然这两个数各自的变化我们不知道,但他们的乘积的变化是一定的,也就是乘上了k^3,那么问题就解决了:只要两个最终分数的乘积是一个完全立方数,那么这组数据就是合法的(前提是这个完全立方数的立方根是这两个数的因数,例如1和8,虽然相乘是2的完全立方,但2并不是1的因数,所以并不合法)。

剩下的就是敲代码了...我采用了纯离线操作...因为a,b的最大值都是10^9, 所以乘积的最大值是10^18,开数组显然开不下,所以用了map...

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int maxn=350000+10;
#define ll long long
unsigned long long a[maxn],b[maxn],tmp;
int main(){
int n;
cin>>n;
map<unsigned long long,int> num;
for(ll i=1;i<=1000000;i++){//10^18是10^6的立方
tmp=i*i*i;
num[tmp]=i;
}
for(int i=1;i<=n;i++)
scanf("%llu %llu",&a[i],&b[i]);
for(int i=1;i<=n;i++){
//cout<<a[i]<<" "<<b[i]<<endl;
if(a[i]==1&&b[i]==1){
printf("Yes\n");
continue;
}
unsigned long long tmpp=a[i]*b[i];
if(num[tmpp]>0){
unsigned long long t=num[tmpp];
if(a[i]%t==0&&b[i]%t==0){
printf("Yes\n");
continue;
}
else printf("No\n");
}
else printf("No\n");
}
return 0;
}

CF833 A The Meaningless Game的更多相关文章

  1. Cassandra - Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless

    In cassandra 2.1.4, if you run "nodetool status" without any keyspace specified, you will ...

  2. C. Meaningless Operations Codeforces Global Round 1 异或与运算,思维题

    C. Meaningless Operations time limit per test 1 second memory limit per test 256 megabytes input sta ...

  3. Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法

    Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. T ...

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

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

  5. Codeforces 834C - The Meaningless Game

    834C - The Meaningless Game 数学. 思路1:判断a•b能不能化成v3且a%v==0且b%v==0.v可以直接用pow求(或者用cbrt),也可以二分求:还可以用map映射预 ...

  6. A. The Meaningless Game(数学)

    A. The Meaningless Game time limit per test:1 second memory limit per test:256 megabytes input:stand ...

  7. Codeforces Round #426 The Meaningless Game

    题目网址:http://codeforces.com/contest/834/problem/C 题目: C. The Meaningless Game Slastyona and her loyal ...

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

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

  9. MDK中问题:warning : type qualifier is meaningless on cast type return 的解决

    在MDK编译代码时,有时会出现这样的警告, warning : type qualifier is meaningless on cast type return 在MDK中,作如下设置: 即添加 : ...

随机推荐

  1. PAT 有几个PAT

    字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T):第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位(T). 现 ...

  2. centos7 yum源更新

    先进入到yum源文件cd /etc/yum.repo.d/  1.创建一个repo_bak目录,用于保存系统中原来yum的repo文件. sudo mkdir repo_bak 2.备份yum源文件至 ...

  3. 我们为什么要用hibernate

    1.hibernate对JDBC访问数据库的代码做了一个封装,简化了数据访问繁琐的代码. 2.hibernate的性能非常好,因为它是个轻量级框架.映射的灵活性很好,它支持各种关系型数据库,从一对一到 ...

  4. 利用java从docx文档中提取文本内容

    利用java从docx文档中提取文本内容 使用Apache的第三方jar包,地址为https://poi.apache.org/ docx文档内容如图: 目录结构: 每个文件夹的名称为日期加上来源,例 ...

  5. Docker学习 ,超全文档!

    我们的口号是:再小的帆也能远航,人生不设限!!        一.学习规划: Docker概述 Docker安装 Docker命令 Docker镜像 镜像命令 容器命令 操作命令 容器数据卷  Doc ...

  6. C Primer Plus(三)

    重读C Primer Plus ,查漏补缺 重读C Primer Plus,记录遗漏的.未掌握的.不清楚的知识点 文件输入/输出 1.fgets函数在读取文件内容时会将换行符读入,但gets不会,fp ...

  7. 【大厂面试08期】谈一谈你对HashMap的理解?

    摘要 HashMap的原理也是大厂面试中经常会涉及的问题,同时也是工作中常用到的Java容器,本文主要通过对以下问题进行分析讲解,来帮助大家理解HashMap的原理. 1.HashMap添加一个键值对 ...

  8. npm设置为淘宝镜像地址

    1. npm设置为淘宝镜像 $npm config set registry https://registry.npm.taobao.org 2. 检查一下 $npm config get regis ...

  9. 迷你图书管理系统 源代码 Java初级小项目

    今天博主再给大家分享一个小项目:MiNi图书管理系统.用的是Java语言开发的,代码不多,大概260行左右吧,系统是实现图书的新增图书.删除图书.借阅图书.归还图书.查看图书等简单的功能(后附源代码) ...

  10. Java WebService(实战) 简单实例

    一.准备工作(以下为本实例使用工具) 1.MyEclipse10.7.1 2.JDK 1.6.0_22 二.创建服务端 1.创建[Web Service Project],命名为[TheService ...