ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203605 | #2424. 记错的欧拉函数 | wosile | 100 | 3595ms | 243820kb | C++11 | 1.6kb | 2024-02-28 11:06:23 | 2024-02-28 12:16:44 |
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
ll n,P;
#define N 5000000
#define M 10000000000000LL
int vis[N+5],p[N+5],cnt=0;
ll pn[N+N];
int h[N+N];
vector<int>hp[N];
int tot=0,inv2;
int G(ll x){
x%=P;
// printf("G[%lld]=%lld\n",x,x*(x+1)%P*inv2%P);
return x*(x+1)%P*inv2%P;
}
void dfs(int x,ll val,int hn){
if(x>cnt || (ll)p[x]*p[x]>n/val)return;
dfs(x+1,val,hn);
if(n/val<(ll)p[x]*p[x])return;
val=val*p[x]*p[x];
int qwerty=2;
while(val<=n){
pn[++tot]=val;
h[tot]=(ll)hn*hp[x][qwerty++]%P;
// printf("h[%d]=%d\n",tot,h[tot]);
dfs(x+1,val,h[tot]);
if(n/val<p[x])break;
val*=p[x];
}
}
int main(){
for(int i=2;i<=N;i++){
if(!vis[i])p[++cnt]=i;
for(int j=1;j<=cnt&&i*p[j]<=N;j++){
vis[i*p[j]]=1;
if(i%p[j]==0)break;
}
}
cin>>n>>P;
for(int i=1;i<=cnt;i++){
hp[i].push_back(1);
hp[i].push_back(0);
ll prod=(ll)p[i]*p[i];
int vf=(ll)p[i]*(p[i]-1)%P;
while(prod<=n){
int val=vf;
ll pd=prod;
for(auto vh:hp[i]){
val=(val-vh*(pd%P)%P+P)%P;
pd/=p[i];
}
// printf("hp[%d][%d]=%d\n",i,hp[i].size(),val);
hp[i].push_back(val);
if(n/p[i]<prod)break;
prod*=p[i];
vf=(ll)vf*(p[i]-1)%P;
}
}
inv2=(P+1)/2;
pn[++tot]=1;
h[tot]=1;
dfs(1,1,1);
// printf("%d\n",tot);
// for(int i=1;i<=tot;i++)printf("%lld ",pn[i]);
// printf("\n");
int ans=0;
for(int i=1;i<=tot;i++)ans=(ans+(ll)h[i]*G(n/pn[i])%P)%P;
printf("%d",ans);
return 0;
}
// quod erat demonstrandum
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 82ms
memory: 150220kb
input:
891 1000339819
output:
310446
result:
ok single line: '310446'
Test #2:
score: 10
Accepted
time: 72ms
memory: 150316kb
input:
8828731 1000513897
output:
930911046
result:
ok single line: '930911046'
Test #3:
score: 10
Accepted
time: 79ms
memory: 150316kb
input:
8623484 1000348849
output:
947064800
result:
ok single line: '947064800'
Test #4:
score: 10
Accepted
time: 105ms
memory: 150320kb
input:
9225731 1000342099
output:
607827377
result:
ok single line: '607827377'
Test #5:
score: 10
Accepted
time: 91ms
memory: 153132kb
input:
8779758004 1000459121
output:
9009652
result:
ok single line: '9009652'
Test #6:
score: 10
Accepted
time: 101ms
memory: 153216kb
input:
9266600688 1000410233
output:
397791282
result:
ok single line: '397791282'
Test #7:
score: 10
Accepted
time: 118ms
memory: 153264kb
input:
9554203275 1000080281
output:
987581088
result:
ok single line: '987581088'
Test #8:
score: 10
Accepted
time: 958ms
memory: 237112kb
input:
8460923373771 1000436687
output:
879988120
result:
ok single line: '879988120'
Test #9:
score: 10
Accepted
time: 1010ms
memory: 243820kb
input:
9829996442877 1000763249
output:
814316622
result:
ok single line: '814316622'
Test #10:
score: 10
Accepted
time: 979ms
memory: 241096kb
input:
9261560116650 1000603447
output:
465112571
result:
ok single line: '465112571'
Extra Test:
score: 0
Extra Test Passed