zoukankan      html  css  js  c++  java
  • CF833A 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 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 kk . 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.

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

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

    输入格式

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

    Each game is represented by a pair of scores a, (b (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).

    样例输入

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

    样例输出

    Yes
    Yes
    Yes
    No
    No
    Yes
    

    题解

    (a)(b)是两个人比赛的得分,对于(a)(b)来说,每轮游戏不是(a=a cdot k,b=b cdot k^2),就是(a=a cdot k^2,b=b cdot k),显然每轮游戏,(a cdot b)的总和都会被乘(k^3),那么对 最后得分 开三次方后是整数,说明可能存在这种情况。

    但是注意,这个条件并不充足。

    还有一个条件,就是开立方的结果是(a)(b)的因数

    (ecause ab=k^{3n})

    $ herefore sqrt[3]{ab} = sqrt[3]{k^{3n}} = k^n $

    设进行了(p)次游戏,(a)(b)最少乘了(p)(k),则(k^n)(开立方结果)一定是(a)(b)的因数

    反过来也成立,当(sqrt[3]{ab}=k^n)是整数 且 (k^n)(a)(b)的因数 时,得分是合法的

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int t;
        scanf("%d", &t);
        while (t--) {
            long long a, b;
            scanf("%lld%lld", &a, &b);
            long long m = pow(a * b, (1.0 / 3)) + 0.5;
            puts((m * m * m != a * b || a % m || b % m) ? "No" : "Yes");
        }
        return 0;
    }
    
    
  • 相关阅读:
    Json字串转换成Java复杂对象
    [Code Snipper]图片轮换
    将CSDN600W用户及密码帐号存入本地MySql数据库
    【转】一个隐形的java int溢出
    【转】展望未来,总结过去10年的程序员生涯,给程序员小弟弟小妹妹们的一些总结性忠告
    如何在Android 4.0 ICS中禁用StatusBar | SystemBar | 状态栏 【完美版】
    【转】提问的智慧(How To Ask Questions the Smart)
    商业开发实战之VB篇精彩视频
    我的设计原语
    RAPIDXML 中文手册,根据官方文档完整翻译!
  • 原文地址:https://www.cnblogs.com/youxam/p/cf833a.html
Copyright © 2011-2022 走看看