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 to , the sum will never be a square number?"
As another reporter in that press conference, you also wondering that given , whether is a square number. Specifically, we regard a positive number as a square number when there exists an integer satisfying .
输入描述
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases.
For each test case, the first line contains one integers .
输出描述
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
输入
1 | 5 |
输出
1 | Fake news! |
分析
打表题,当且仅当 或 时, 为完全平方数。
知乎上的巨佬们给出了一些证明。
代码
1 | /****************************************************************** |
H. Dividing
题目描述
The following rules define a kind of integer tuple - the Legend Tuple:
is always a Legend Tuple, where k is an integer.
if is a Legend Tuple, is also a Legend Tuple.
if is a Legend Tuple, is also a Legend Tuple.
We want to know the number of the Legend Tuples where , .
In order to avoid calculations of huge integers, report the answer modulo instead.
输入描述
The input contains two integers and , .
输出描述
Output the answer modulo .
示例1
输入
1 | 3 3 |
输出
1 | 8 |
示例2
输入
1 | 3 9 |
输出
1 | 14 |
分析
所有 Legend Tuple 从 出发,会产生 和 两种情况();其中, 的情况经过一步操作可以变成 的情况。
显然,当且仅当 或 时, 为 Legend Tuple。
对于 的情况,其贡献为 ; 为 的贡献, 为 的贡献。
对于 的情况,其贡献为 。
对于两部分贡献,有 这部分的贡献是重复的,需要减去重复的一份贡献 。
因此最终的答案为 。可以用数论分块解决。
当然, 或 时需要进行特判:当 ,答案为 ;当 ,答案为 。
代码
1 | /****************************************************************** |