【CodeForces - 833A】The Meaningless Game(思维题,数学,可用牛顿迭代法,知识点总结)

题干:

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 k 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 k2, 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 n 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.

Input

In the first string, the number of games n (1 ≤ n ≤ 350000) is given.

Each game is represented by a pair of scores ab (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly.

Output

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

Example

Input

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

Output

Yes
Yes
Yes
No
No
Yes

Note

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

题目大意:

        有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数

解题思路:将两个人的分数相乘然后开立方即可

解题报告:

        这题要注意,pow和sqrt返回的都是double型,如果强转一下,默认向下取整,所以这里需要四舍五入,用round函数。

 

ps一个题解:题解、、

题意
有n(1<=n<=350000)场游戏,对于每场游戏有若干个回合组成,两个人的初始分均为1,每个回合赢的人当前分数乘上k^2,输的人当前分数乘上k(每一回合的k都是不同的)。给你两个数a,b(1<=a,b<=10^9)问你这两个数是否为他们最终的分数?
思路:
我们先计算a*b,那么考虑a*b=(k_1^3)(k_2^3)(k_i^3),即a*b为立方数的乘积组成,我们可以二分找出满足a*b=mid^3,我们判断mid是否等于k_1*k_2…*k_i。
当且仅当存在a*b=mid^3,a%mid=0,b%mid=0,那么a,b就为他们最终的分数,反之不是。

AC代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;int main()
{int t,a,b;cin>>t;while(t--) {scanf("%d%d",&a,&b);int tmp = round(pow(1.0*a*b,1.0/3));if(a*b == tmp*tmp*tmp && a%tmp==0 & b%tmp==0) puts("Yes");else puts("No");}return 0 ;
}

这个pow开三次方,不知道是怎么做的。

附一种 牛顿迭代法开立方根的方法:

#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;
#define double long doubleconst double eps = 1e-1;
double sqrt3(double x) {double r = x;double f = 1, k;do {f = r * r * r - x;k = 3 * r * r;r -= f / k;} while (f > eps);return r;
}int a, b;
long long P;
inline void init() {scanf("%d%d", &a, &b);P = a * 1LL * b;
}inline boolean solve() {long long x = sqrt3(P);if(x * x * x != P)    return false;return !(a % x || b % x);
}int T;
int main() {scanf("%d", &T);while(T--) {init();puts(solve() ? ("Yes") : ("No"));}return 0;
}

二分求解:

#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;
#define LL long longint sqrt3(LL x) {int l = 1, r = 1e6;while(l <= r) {LL mid = (l + r) >> 1;if(mid * mid * mid <= x)    l = mid + 1;else r = mid - 1;}return l - 1;
}int a, b;
long long P;
inline void init() {scanf("%d%d", &a, &b);P = a * 1LL * b;
}inline boolean solve() {long long x = sqrt3(P);if(x * x * x != P)    return false;return !(a % x || b % x);
}int T;
int main() {scanf("%d", &T);while(T--) {init();puts(solve() ? ("Yes") : ("No"));}return 0;
}

Hash的方法:

#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;
#define LL long longconst int limit = 1e6;
LL arr3[limit + 1];
inline void rinit() {for(int i = 1; i <= limit; i++)arr3[i] = i * 1LL * i * i;
}int a, b;
long long P;
inline void init() {scanf("%d%d", &a, &b);P = a * 1LL * b;
}inline boolean solve() {int x = lower_bound(arr3 + 1, arr3 + limit + 1, P) - arr3;if(arr3[x] != P)    return false;return !(a % x || b % x);
}int T;
int main() {rinit();scanf("%d", &T);while(T--) {init();puts(solve() ? ("Yes") : ("No"));}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441769.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python创建变量并赋值_python怎么给变量赋值

在学习变量及赋值之前,我们要知道什么是变量! Python语言中,用等号【=】来表示赋值,Python赋值并不是直接将一个值赋值给一个变量,在Python中,对象是通过引用传递的;在传递时,不管这个对象是新创建的还是已经存在的,都是将该对象的引用赋值给变量。 举个例子,3 * 4 =…

正则表达式 python_Python正则表达式总结

之前我们讲解了 正则表达式 的起源、发展、流派、语法、引擎、优化等相关知识&#xff0c;今天我们主要来学习一下 正则表达式在 Python语言 中的应用&#xff01;大多数编程语言的正则表达式设计都师从Perl&#xff0c;所以语法基本相似&#xff0c;不同的是每种语言都有自己的…

【HDU - 5912】Fraction (模拟)

题干&#xff1a; Mr. Frog recently studied how to add two fractions up, and he came up with an evil idea to trouble you by asking you to calculate the result of the formula below: As a talent, can you figure out the answer correctly? Input The first …

vue mysql webapp_基于Laravel+VueJS实战开发WebAPP

资源介绍【课程内容】1-git库与开发环境及工具软件介绍2-安装laravel框架3-安装laravel-ide-helper增强代码提示4-配置数据库与使用migrations创建表5-解决mysql5.7以下laravel不能执行数据迁移的问题6-合理的路由布局与分组路由7-远程开发环境服务器搭建与虚拟面板的使用8-使用…

计算机测试怎么提交,Win7电脑怎么测试上传速度?

做网站的人都知道上传速度是很重要的&#xff0c;因为太差的上传速度会影响工作的进度&#xff0c;所以他们经常要对上传速度进行测试&#xff0c;但是有一些新手不知道Win7电脑怎么测试上传速度&#xff1f;为此小编赶紧整理了以下教程&#xff0c;不知道的朋友赶紧来看看吧&a…

harmonyos消息服务器,第三方纯HarmonyOS应用太少,你还愿意升级吗?

部分纯鸿蒙 HarmonyOS 应用已上线&#xff1a;图标多了“HMOS”角标标识&#xff0c;而只有真正的鸿蒙系统应用才能真正体验到万能卡片等系列的功能&#xff0c;但是很明显目前真正属于鸿蒙系统的第三方应用太少……基本上都是华为自身的应用&#xff0c;那么如果应用太少你还愿…

300英雄服务器维护多久,《300英雄》2021年5月20日6:00-9:00更新维护公告

尊敬的《300英雄》玩家:《300英雄》将于2021年5月20日6:00-9:00(星期四)&#xff0c;对所有大区进行停机更新&#xff0c;更新期间&#xff0c;您将无法登录游戏。如果在预定时间内无法完成维护内容&#xff0c;开服时间也将继续顺延。具体更新内容如下&#xff1a;一、活动相关…

服务器2008系统如何设置休眠时间,Win7休眠和睡眠怎么开启(Win2008)

如果把 Win7休眠和睡眠关闭了&#xff0c;需要的时候可以用命令重新开启&#xff0c;毕竟这两个功能不但可以节约电&#xff0c;还可以迅速恢复工作状态&#xff0c;节约开机开软件的时间。Win2008 R2 跟 Win7 同一内核&#xff0c;开启休眠和睡眠的命令也一样。在开启休眠和睡…

如何将文件拷贝服务器上,如何将文件复制到云服务器上

如何将文件复制到云服务器上 内容精选换一换将文件上传至Windows云服务器一般会采用MSTSC远程桌面连接的方式。本节为您介绍本地Windows计算机通过远程桌面连接&#xff0c;上传文件至Windows云服务器的操作方法。Windows云服务器可以访问公网。在本地Windows计算机上&#xff…

mysql5.7解压版错误_mysql 5.7 解压版 安装net start mysql 发生系统错误 2

1.配置环境变量 用户变量path 添加 mysql 安装目录2.新建my.ini文件 放到E:\mysql-5.7.24-winx64安装目录下[mysqld]port 3306basedirC:/software/mysql-5.7.21-winx64datadirC:/software/mysql-5.7.21-winx64/datamax_connections200character-set-serverutf8default-storage…

浪潮服务器建立虚拟驱动器,像《十二时辰》一样去建立标准! 浪潮这款服务器做到了...

原标题&#xff1a;像《十二时辰》一样去建立标准&#xff01; 浪潮这款服务器做到了这个夏天&#xff0c;《长安十二时辰》制霸屏幕开画至今豆瓣评分达到8.8分现已成功“出海”在Amazon、Youtube、Viki付费上线成为唐风古韵的又一风向标现如今&#xff0c;越洋的标准可不止悠悠…

【AtCoder - 2554】Choose Integers (找规律,或枚举)

题干&#xff1a; Problem Statement We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each sele…

1m带宽可以做mysql数据库吗_服务器的1M带宽够用吗?1M网速是多少?

1M是什么&#xff1f;通常&#xff0c;在计算机中1M表示的是计算机的内存容量&#xff0c;即1M1024KB。但有不同的含义&#xff0c;云服务器中1M表示服务器的带宽&#xff0c;即1M带宽。在服务器中1M带宽够用吗&#xff1f;云服务器的1兆网速是多少&#xff1f;首先把云服务器带…

【POJ - 2318】TOYS(计算几何,叉积判断点与直线位置关系,二分)

题干&#xff1a; Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave John a rectangular box to put his toys i…

【HDU - 1968】【UVA - 12096】The SetStack Computer (模拟,集合求交集并集操作,STL实现)

题干&#xff1a; Background from Wikipedia: 揝et theory is a branch of mathematics created principally by the German mathematician Georg Cantor at the end of the 19th century. Initially controversial, set theory has come to play the role of a foundational…

【HDU - 1465 】不容易系列之一 (组合数学,错排)

题干&#xff1a; 大家常常感慨&#xff0c;要做好一件事情真的不容易&#xff0c;确实&#xff0c;失败比成功容易多了&#xff01; 做好“一件”事情尚且不易&#xff0c;若想永远成功而总从不失败&#xff0c;那更是难上加难了&#xff0c;就像花钱总是比挣钱容易的道理一…

java redis 重连_突破Java面试(23-4) - Redis 复制原理

全是干货的技术号&#xff1a;本文已收录在github&#xff0c;欢迎 star/fork&#xff1a;在Redis复制的基础上(不包括Redis Cluster或Redis Sentinel作为附加层提供的高可用功能)&#xff0c;使用和配置主从复制非常简单&#xff0c;能使得从 Redis 服务器(下文称 slave)能精确…

python列表浅复制_Python列表深浅复制详解

转自&#xff1a;https://www.cnblogs.com/blaomao/p/7239203.html在文章《Python 数据类型》里边介绍了列表的用法&#xff0c;其中列表有个 copy() 方法&#xff0c;意思是复制一个相同的列表。例如1 names ["小明", "小红", "小黑", "小…

【CodeForces - 735B】Urbanization (找规律,思维)

题干&#xff1a; Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to a…

java 文本查找_Java基于正则表达式实现查找匹配的文本功能【经典实例】

本文实例讲述了Java基于正则表达式实现查找匹配的文本功能。分享给大家供大家参考&#xff0c;具体如下&#xff1a;REMatch.java&#xff1a;package reMatch;import java.util.regex.Matcher;import java.util.regex.Pattern;/*** Created by Frank*/public class REMatch {p…