求助CE
  • 板块灌水区
  • 楼主Prean
  • 当前回复2
  • 已保存回复2
  • 发布时间2020/5/3 15:41
  • 上次更新2023/11/7 03:16:44
查看原帖
求助CE
160839
Prean楼主2020/5/3 15:41

记录

请问这种CE是怎么回事?本地没问题的啊?

Code:

#include<unordered_map>
#include<iostream>
#include<cstdio>
#include<cctype>
#define ll __int128
const int M=4641590;
ll n,inv,mod,ans,phi[M|5];int top,pri[M|5],zhi[M|5];
std::unordered_map<ll,ll>Sphi;
inline ll Get1(ll n){n%=mod;return n*(n+1)%mod*(2*n+1)%mod*inv%mod;}
inline ll Get2(ll n){n%=mod;return (n*(n+1)/2)%mod*((n*(n+1)/2)%mod)%mod;}
inline ll pow(ll a,ll b,ll p)
{
	ll ans=1;for(;b;b>>=1,a=a*a%p)if(b&1)ans=ans*a%p;
	return ans;
}
inline ll GetSphi(ll n)
{
	if(n<=M)return phi[n];
	if(Sphi.find(n)!=Sphi.end())return Sphi[n];
	ll ans=Get2(n);
	for(ll L=2,R;L<=n;L=R+1)
	{
		R=n/(n/L);
		ans=(ans-(Get1(R)-Get1(L-1)+mod)%mod*GetSphi(n/L)%mod)%mod;
	}
	return Sphi[n]=(ans+mod)%mod;
}
inline std::istream&operator>>(std::istream&a,ll&n)
{
	char s;int f=1;while(!isdigit(s=getchar()))if(s==45)f=-1;n=0;
	while(n=n*10+(s^48),isdigit(s=getchar()));n*=f;return a;
}
inline std::ostream&operator<<(std::ostream&a,ll n)
{
	char s[105];int top=0;while(s[++top]=n%10+'0',n/=10);
	while(putchar(s[top--]),top);return a;
}
signed main()
{
	int i,j,x;zhi[1]=phi[1]=1;
	std::cin>>mod>>n;inv=pow(6,mod-2,mod);
	for(i=2;i<=M;++i)
	{
		if(!zhi[i])pri[++top]=i,phi[i]=i-1;
		for(j=1;j<=top&&(x=i*pri[j])<=M;++j)
		{
			zhi[x]=1;
			if(i%pri[j])phi[x]=phi[i]*(pri[j]-1);
			else{phi[x]=phi[i]*pri[j];break;}
		}
		phi[i]=(phi[i-1]+phi[i]%mod*i*i%mod)%mod;
	}
	for(ll L=1,R;L<=n;L=R+1)
	{
		R=n/(n/L);
		ans=(ans+(GetSphi(R)-GetSphi(L-1)+mod)%mod*Get2(n/L)%mod)%mod;
	}
	std::cout<<(ans+mod)%mod;
}
2020/5/3 15:41
加载中...