程序解答高数方程
题目大意
给定一个数字 n,问是否存在 x 满足 x 2 = K2
输入描述
There are multiple test cases. The first line of the input contains an integer T (1 ≤ T ≤ 1e6) indicating the number of test cases.
For each test case, the first line contains one integers n (1 ≤ n≤ 1e15 ).
输出描述
If the sum is a square number, please output ‘Fake news!’ in one line. Otherwise, please output ‘Nobody knows it better than me!’ instead.
输入
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!
解题思路
我们可以先在本地打表测试一下哪些数字满足条件,打完表后发现只有两个数满足条件,故我们直接特判这两个数就好了
cin 和 cout 加速之后还是会被 T 掉的,直接上 scanf 和 printf 就可以 ac
至于为什么是 1 和 24 ,其实是可以证明出来的 知乎的证明帖子 - 传送门
AC代码
#include<iostream> #include<algorithm> #include<string.h> #include<string> #include<cmath> #include<cstdio> #include<cstdlib> using namespace std; typedef long long ll; //const int maxn = 1e8; //double sum[maxn]; //void table() //{ // sum[0] = 0; // for(int i = 1 ; i <= maxn ; i++) // { // sum[i] += i*i + sum[i-1]; // int tmp = sqrt(sum[i]); // if(tmp * tmp == sum[i]) // { // cout<<"sum["<<i<<"] = "<<sum[i]<<endl; // } // } //} int main() { //ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); //table(); int t; scanf("%d",&t); while(t--) { char n[20]; scanf("%s",n); if(strlen(n) == 1 && n[0] == '1') { printf("Fake news!\n"); }else if(strlen(n) == 2 && n[0] == '2' && n[1] == '4') { printf("Fake news!\n"); }else { printf("Nobody knows it better than me!\n"); } } return 0; }
本文地址:https://blog.csdn.net/weixin_46425926/article/details/107730521
上一篇: 很深很浑浊 超低价时代购买液晶四点需牢记
下一篇: SketchUp怎么设计长腿板凳?