ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203672 | #23. A | wosile | 100 | 952ms | 37248kb | C++11 | 1.4kb | 2024-03-07 10:28:24 | 2024-03-07 14:18:33 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
int n,mod;
#define M 3000000
int phi[3000005],p[3000005],vis[3000005];
int sumphi[3000005];
int cnt=0,inv6;
map<int,int>mp;
int qp(int x,int y){
int ans=1;
while(y){
if(y&1)ans=(ll)ans*x%mod;
y>>=1;
x=(ll)x*x%mod;
}
return ans;
}
int fsum(int x){
return (ll)x*(x+1)%mod*(x+x+1)%mod*inv6%mod;
}
int Phi(int x){
if(x<=M)return sumphi[x];
if(mp.find(x)!=mp.end())return mp[x];
int ans=(ll)x*(x+1)/2%mod;
int L=2;
while(L<=x){
int R=x/(x/L);
ans=(ans-(ll)(R-L+1)*Phi(x/L))%mod;
L=R+1;
}
return mp[x]=(ans+mod)%mod;
}
int main(){
vis[1]=1,phi[1]=1;
for(int i=2;i<=M;i++){
if(!vis[i])p[++cnt]=i,phi[i]=i-1;
for(int j=1;j<=cnt&&i*p[j]<=M;j++){
vis[i*p[j]]=1;
if(i%p[j]==0){
phi[i*p[j]]=phi[i]*p[j];
break;
}
phi[i*p[j]]=phi[i]*phi[p[j]];
}
}
scanf("%d%d",&n,&mod);
for(int i=1;i<=M;i++)sumphi[i]=(sumphi[i-1]+phi[i])%mod;
// for(int i=1;i<=n;i++)printf("%d ",sumphi[i]);printf("\n");
inv6=qp(6,mod-2);
int L=1,ans=0;
while(L<=n){
int R=n/(n/L);
// printf("%d %d %d\n",fsum(n/L),Phi(R),Phi(L-1));
ans=(ans+(ll)fsum(n/L)*(Phi(R)-Phi(L-1)))%mod;
L=R+1;
}
printf("%d",(ans+mod)%mod);
return 0;
}
// quod erat demonstrandum
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 65ms
memory: 37196kb
input:
11 998244353
output:
651
result:
ok 1 number(s): "651"
Test #2:
score: 10
Accepted
time: 70ms
memory: 37196kb
input:
60 1000000009
output:
101457
result:
ok 1 number(s): "101457"
Test #3:
score: 10
Accepted
time: 72ms
memory: 37192kb
input:
73 998244353
output:
180007
result:
ok 1 number(s): "180007"
Test #4:
score: 10
Accepted
time: 78ms
memory: 37236kb
input:
9039240 1000000009
output:
443974844
result:
ok 1 number(s): "443974844"
Test #5:
score: 10
Accepted
time: 72ms
memory: 37236kb
input:
9196294 1000000009
output:
391130254
result:
ok 1 number(s): "391130254"
Test #6:
score: 10
Accepted
time: 70ms
memory: 37236kb
input:
9775622 1000000009
output:
764138175
result:
ok 1 number(s): "764138175"
Test #7:
score: 10
Accepted
time: 133ms
memory: 37244kb
input:
957560129 1000000007
output:
52164784
result:
ok 1 number(s): "52164784"
Test #8:
score: 10
Accepted
time: 132ms
memory: 37244kb
input:
951882222 998244353
output:
30965363
result:
ok 1 number(s): "30965363"
Test #9:
score: 10
Accepted
time: 126ms
memory: 37248kb
input:
928738646 1000000007
output:
981655745
result:
ok 1 number(s): "981655745"
Test #10:
score: 10
Accepted
time: 134ms
memory: 37244kb
input:
911039034 1000000009
output:
726376639
result:
ok 1 number(s): "726376639"
Extra Test:
score: 0
Extra Test Passed