D. Fake News \looparrowright

题目描述

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 11 to nn, the sum will never be a square number?"
As another reporter in that press conference, you also wondering that given nn, whether k=1nk2\sum\limits_{k=1}^{n}k^2 is a square number. Specifically, we regard a positive number xx as a square number when there exists an integer yy satisfying y2=xy^2=x.

输入描述

There are multiple test cases. The first line of the input contains an integer T (1T106)T\ (1 \leqslant T \leqslant 10^6) indicating the number of test cases.
For each test case, the first line contains one integers n (1n1015)n\ (1 \leqslant n \leqslant 10^{15}).

输出描述

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
2
3
4
5
6
5
1
2
3
4
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=1n=1n=24n=24 时,k=1nk2\sum\limits_{k=1}^nk^2 为完全平方数。
知乎上的巨佬们给出了一些证明

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/******************************************************************
Copyright: 11D_Beyonder All Rights Reserved
Author: 11D_Beyonder
Problem ID: 2020牛客暑期多校训练营(第七场)Problem D
Date: 8/27/2020
Description: Just Attempt
*******************************************************************/
#include<stdio.h>
int main(){
int _;
for(scanf("%d",&_);_;_--){
long long n;
scanf("%lld",&n);
if(n==1||n==24){
puts("Fake news!");
}else{
puts("Nobody knows it better than me!");
}
}
return 0;
}

H. Dividing \looparrowright

题目描述

The following rules define a kind of integer tuple - the Legend Tuple:
(1,k)(1, k) is always a Legend Tuple, where k is an integer.
if (n,k)(n, k) is a Legend Tuple, (n+k,k)(n + k, k) is also a Legend Tuple.
if (n,k)(n, k) is a Legend Tuple, (nk,k)(nk, k) is also a Legend Tuple.
We want to know the number of the Legend Tuples (n,k)(n, k) where 1nN1 \leqslant n \leqslant N, 1kK1 \leqslant k \leqslant K.
In order to avoid calculations of huge integers, report the answer modulo 109+710^9+7 instead.

输入描述

The input contains two integers NN and KK, 1N,K10121 \leqslant N, K \leqslant 10^{12}.

输出描述

Output the answer modulo 109+710^9+7.

示例1

输入

1
3 3

输出

1
8

示例2

输入

1
3 9

输出

1
14

分析

所有 Legend Tuple(1,k)(1,k) 出发,会产生 (xk,k)(xk,k)(xk+1,k)(xk+1,k) 两种情况(xNx\in\mathbb N^\ast);其中,(xk+1,k)(xk+1,k) 的情况经过一步操作可以变成 (xk,k)(xk,k) 的情况。
显然,当且仅当 k(n1)k\mid (n-1)knk\mid n 时,(n,k)(n,k)Legend Tuple
对于 k(n1)k\mid(n-1) 的情况,其贡献为 k=1Kn=1N[k(n1)]=k=1KN1k+K\sum\limits_{k=1}^K\sum\limits_{n=1}^N\left[k\mid(n-1)\right]=\sum\limits_{k=1}^K\left\lfloor\frac{N-1}{k}\right\rfloor+Kk=1KN1k\sum\limits_{k=1}^K\left\lfloor\frac{N-1}{k}\right\rfloorn2n\geqslant 2 的贡献,KKn=1n=1 的贡献。
对于 knk\mid n 的情况,其贡献为 k=1Kn=1N[kn]=k=1KNk\sum\limits_{k=1}^K\sum\limits_{n=1}^N [k\mid n]=\sum\limits_{k=1}^K\left\lfloor\frac{N}{k}\right\rfloor
对于两部分贡献,有 (1,1),(2,1),,(N,1)(1,1),(2,1),\cdots,(N,1) 这部分的贡献是重复的,需要减去重复的一份贡献 NN
因此最终的答案为 k=1Kn=1N[kn]=k=1KNk+k=1Kn=1N[k(n1)]=k=1KN1k+KN\sum\limits_{k=1}^K\sum\limits_{n=1}^N [k\mid n]=\sum\limits_{k=1}^K\left\lfloor\frac{N}{k}\right\rfloor+\sum\limits_{k=1}^K\sum\limits_{n=1}^N\left[k\mid(n-1)\right]=\sum\limits_{k=1}^K\left\lfloor\frac{N-1}{k}\right\rfloor+K-N。可以用数论分块解决。
当然,N=1N=1K=1K=1 时需要进行特判:当 N=1N=1,答案为 KK;当 K=1K=1,答案为 NN

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/******************************************************************
Copyright: 11D_Beyonder All Rights Reserved
Author: 11D_Beyonder
Problem ID: 2020牛客暑期多校训练营(第七场)Problem H
Date: 8/28/2020
Description: Block
*******************************************************************/
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
ll N,K;
ll cal(ll n,ll k){
//数论分块
ll l,r;
ll ans=0;
for(l=1;l<=k;l=r+1){
if(n/l==0){
break;
}
r=min(k,n/(n/l));
ans+=(r-l+1)*(n/l)%mod;
ans%=mod;
}
return ans;
}
int main(){
cin>>N>>K;
if(N==1){
cout<<K%mod<<endl;
}else if(K==1){
cout<<N%mod<<endl;
}else{
cout<<((cal(N,K)+cal(N-1,K)+K-N)%mod+mod)%mod<<endl;
}
return 0;
}