zoukankan      html  css  js  c++  java
  • 牛客多校(2020第七场) D-Fake News

    题目描述

    McDonald Thumb, the greatest president ever in the history of the Great Tokitsukaze Kingdom has held his 100th press conference about the global pandemic after making his 1000000th tweets with his smartphone. With a big smile on his face, Mr. Thumb said that nobody knows math more than he does. 

    ‘I learn math since I was born and I am very good at it’, said Mr. Thumb. ‘People keep asking me why I know math so much and I sometimes find myself having those amazing ideas about math.’ 

    ‘For example?’, asked by a reporter. 

    ‘Oh you, I know you! Fake news! You and your agency always produce fake news!’, replied angrily by Mr. Thumb. ‘Let me teach you something, do you know if you add up the squares of numbers from 1 to n, the sum will never be a square number?’
    As another reporter in that press conference, you also wondering that given n, whether ∑k=1nk2sum_{k=1}^{n}k^2k=1nk2 is a square number. Specifically, we regard a positive number x as a square number when there exists an integer y satisfying y2=xy^2=xy2=x.

    输入描述:

    There are multiple test cases. The first line of the input contains an integer T (1≤T≤106)(1 leq T leq 10^6)(1T106) indicating the number of test cases. 

    For each test case, the first line contains one integers n (1≤n≤1015)(1 leq n leq 10^{15})(1n1015).

    输出描述:

    If the sum is a square number, please output ‘Fake news!’ in one line. Otherwise, please output ‘Nobody knows it better than me!’ instead.
    示例1

    输入

    5
    1
    2
    3
    4
    5

    输出

    Fake news!
    Nobody knows it better than me!
    Nobody knows it better than me!
    Nobody knows it better than me!
    Nobody knows it better than me!

    题解:
    就是给定一个整数n,求1-n的平方和是否是平方数(另一个数字的平方),可进行打表寻找规律,发现当且仅当n==1 || n==24时,其结果是平方数
     1 #include<iostream>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 
     6 long long n;
     7 
     8 int main() {
     9     ios::sync_with_stdio(false); //注意:不加这几条会TL
    10     cin.tie(0);
    11     cout.tie(0);
    12     int t;
    13     cin >> t;
    14     while (t--) {
    15         cin >> n;
    16         if (n == 1 || n == 24)  cout << "Fake news!
    ";
    17         else cout << "Nobody knows it better than me!
    ";
    18     }
    19 }
     
           
          
     
  • 相关阅读:
    Ubuntu 出现apt-get: Package has no installation candidate问题
    关于Linux下如何获取计算机的硬件信息
    分享自fissure 《Linux编程 报错 找不到 term.h和curses.h》
    亚稳态-竺清儿-ChinaUnix博客
    分享自yebai445791253 《Verilog $random用法》
    CodeForces 1288D. Minimax Problem (二分+位运算)
    CodeForces 705D. Ant Man 贪心+链表
    CodeForces 832D. Misha, Grisha and Underground LCA
    CodeForces 832C. Strange Radiation 二分
    CodeForces 1102F. Elongated Matrix 状压Dp
  • 原文地址:https://www.cnblogs.com/mr-wei977955490/p/15367588.html
Copyright © 2011-2022 走看看