【luogu3768】简单的数学题

Source

luogu3768

Hint

请先思考后再展开

$\varphi \ast I = id$
$\sum i^k$ 是多项式,可高斯消元求通项公式

Solution

请先思考后再展开

yyb
补充一下复杂度,尽管有根号次询问,但都是n/i的各种取值下不同的i,
尽管有整除但应该不会太多,所以记忆化后总复杂度是对的

这题有个类似的题hihocoder1456-zjp
就是前面套了个模型转化

code:

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//Zory-2019
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
typedef long long ll;
#define double long double
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3fll;
ll qread()
{
ll ans=0;char c=getchar();int f=1;
while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
return ans*f;
}
void write(ll num)
{
if(num<0) {num=-num;putchar('-');}
if(num>9) write(num/10);
putchar('0'+num%10);
}
void write1(ll num){write(num);putchar(' ');}
void write2(ll num){write(num);puts("");}
#define FR first
#define SE second
#define MP make_pair
#define pr pair<int,int>
#define PB push_back
#define vc vector
void chmax(int &x,const int y) {x=x>y?x:y;}
void chmin(ll &x,const int y) {x=x<y?x:y;}
const int MAX_N=1e7+10;
ll MOD;
void add(int &x,int y) {x+=y;if(x>=MOD) x-=MOD;if(x<0) x+=MOD;}
ll qpower(ll x,ll e)
{
ll ans=1;
while(e)
{
if(e&1) ans=ans*x%MOD;
x=x*x%MOD;e>>=1;
}
return ans;
}
ll inv(ll x){return qpower(x,MOD-2);}
bool mark[MAX_N];int pp=0,prime[MAX_N/10];
ll f[MAX_N];
void pre()
{
f[1]=1;
for(int i=2;i<MAX_N;i++)
{
if(!mark[i]) prime[++pp]=i,f[i]=i-1;
for(int j=1;j<=pp and (ll)i*prime[j]<MAX_N;j++)
{
int t=i*prime[j];mark[t]=1;
if(i%prime[j]==0){f[t]=f[i]*prime[j];break;}
f[t]=f[i]*(prime[j]-1);
}
}
for(int i=1;i<MAX_N;i++) f[i]=(f[i-1]+f[i]*i%MOD*i%MOD)%MOD;
}
ll inv4;ll H(ll n){n%=MOD;return n*n%MOD*(n+1)%MOD*(n+1)%MOD*inv4%MOD;}
ll inv6;ll G(ll n){n%=MOD;return n*(n+1)%MOD*(n*2+1)%MOD*inv6%MOD;}
map<int,ll> hash;
ll getF(ll n)
{
if(n<MAX_N) return f[n];
if(hash.count(n)) return hash[n];
ll ans=H(n);
for(ll l=2,r;l<=n;l=r+1) r=n/(n/l),ans=(ans-getF(n/l)*(G(r)-G(l-1))%MOD)%MOD;
return hash[n]=ans;
}
void main()
{
MOD=qread();ll n=qread();
inv4=inv(4);inv6=inv(6);pre();getF(n);
ll ans=0;for(ll l=1,r;l<=n;l=r+1) r=n/(n/l),ans+=H(n/l)*(getF(r)-getF(l-1))%MOD;
write((ans%MOD+MOD)%MOD);
}
};
signed main()
{
srand(time(0));
mine::main();
}

本文基于 知识共享署名-相同方式共享 4.0 国际许可协议发布
本文地址:http://zory.ink/posts/8859.html
转载请注明出处,谢谢!