40pts求调qwq
查看原帖
40pts求调qwq
100325
peterwuyihong楼主2021/6/22 10:13
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<' '<<x<<endl
#ifndef ONLINE_JUDGE
	#define pia getchar
#else
	#define pia nc
#endif
char nc(){
  	static char buf[1<<25],*p=buf,*q=buf;
  	if(p==q&&(q=(p=buf)+fread(buf,1,1<<25,stdin),p==q))return EOF;
  	return *p++;
}
template<class T>void rd(T&x){
	short f=1;x=0;
	char ch=pia();
	while(!isdigit(ch)){
		if(ch=='-')f=-1;
		ch=pia();
	}while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=pia();
	}x*=f;
}
template<class T>void wr(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)wr(x/10);
	putchar(x%10+48);
}
#define int long long
#define maxn 210622
int RD(){int tmp;rd(tmp);return tmp;}
const int N=RD();
const int K=RD();
const int p=RD();
const int lim=sqrt((long long)N);
int ksm(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=a*a%p)
	if(b&1)ans=ans*a%p;
	return ans;
}
const int INV_K_PLUS_ONE=ksm(K+1,p-2);
int pri[maxn],pcnt,lpf[maxn],sprik[maxn];
int prik[maxn];
void shai(int n){
	for(int i=2;i<=n;i++){
		if(lpf[i]==0){
			pri[lpf[i]=++pcnt]=i;
			prik[pcnt]=ksm(i,K);
			sprik[pcnt]=(sprik[pcnt-1]+prik[pcnt])%p;
		}
		for(int j=1;j<=lpf[i]&&i*pri[j]<=n;j++)lpf[i*pri[j]]=j;
	}
}
#define id(x) ((x)<=lim?le[x]:ge[N/(x)])
int ge[maxn],le[maxn];
int li[maxn];
int G[maxn],tot;
int B[11]={1, p-1, 1, 0, p-1, 0, 1, 0, p-1, 0, 5};
int BB[11]={1, 2, 6, 1, 30, 1, 42, 1, 30, 1, 66};
int jc[12]={1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800};
int jcinv[12];
int C(int n,int m){
	return jc[n]*jcinv[m]%p*jcinv[n-m]%p;
}
int S(int n){
	int ans=0;
	for(int i=0;i<=K;i++)ans=(ans+C(K+1,i)*B[i]%p*ksm(1+n,K-i+1))%p;
	ans=ans*INV_K_PLUS_ONE%p;
	return ans;
}
void init(){
	for(int i=1,j;i<=N;i=N/j+1){
		j=N/i;
		const int v=j%p;
		li[++tot]=v;
		id(j)=tot;
		G[tot]=(S(v)-S(1)+p)%p;
	}
}
void calcFprime(){
	for(int k=1;k<=pcnt;k++)
	for(int i=1;li[i]>=pri[k]*pri[k];i++){
		int d=id(li[i]/pri[k]);
		G[i]=(G[i]+(p-prik[k])*(G[d]-sprik[k-1]+p))%p;
	}
}
signed main(){
	for(int i=0;i<=10;i++)B[i]=B[i]*ksm(BB[i],p-2)%p;
	jcinv[11]=ksm(jc[11],p-2);
	for(int i=10;i>=0;i--)jcinv[i]=jcinv[i+1]*(i+1)%p;
	shai(lim+1000);
	init();
	calcFprime();
	int ans=0;
	for(int i=1;i<=lim;i++)ans=(ans+G[i]*i%p*i)%p;
	wr(ans);
}

样例都是对的,交上去愣是40pts40pts,有点网抑

2021/6/22 10:13
加载中...