如果i是奇数,那么2没有算过,个数+1,平方和+4
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #define maxn 10000100 #define mod 1000000007 using namespace std; int prime[maxn],a[maxn],cnt[maxn]; long long b[maxn],pow[maxn],sum[maxn]; bool vis[maxn]; int n,m,ans,tot; long long Ans; int T,q1,A,B,C; int main() { scanf("%d",&T); scanf("%d%d%d%d",&q1,&A,&B,&C); n=C;a[1]=1;b[1]=1; for (int i=2;i<=n;i++) { if (!vis[i]) { prime[++tot]=i; a[i]=2;cnt[i]=1;sum[i]=b[i]=1+(long long)i*i;pow[i]=i; } for (int j=1;j<=tot && i*prime[j]<=n;j++) { vis[i*prime[j]]=1; if (i%prime[j]==0) { cnt[i*prime[j]]=cnt[i]+1; a[i*prime[j]]=a[i]/(cnt[i]+1)*(cnt[i]+2); pow[i*prime[j]]=(long long)pow[i]*prime[j]; sum[i*prime[j]]=sum[i]+(long long)pow[i*prime[j]]*pow[i*prime[j]]; b[i*prime[j]]=b[i]/sum[i]*sum[i*prime[j]]; break; } a[i*prime[j]]=a[i]*2; cnt[i*prime[j]]=1; pow[i*prime[j]]=prime[j]; sum[i*prime[j]]=1+(long long)prime[j]*prime[j]; b[i*prime[j]]=sum[i*prime[j]]*b[i]; } } for (int i=1;i<=T;i++,q1=((long long)q1*A+B)%C+1) { Ans=(Ans+b[q1])%mod,ans=(ans+a[q1])%mod; if (q1&1) Ans=(Ans+4)%mod,ans=(ans+1)%mod; } printf("%d\n%lld\n",ans,Ans); return 0; }