是个结论题
= =好像当天状态不好直接抄的题解啊
第一问,欧拉筛
第二问,欧拉筛约数平方和
感觉自己好弱欧拉筛都不会写了
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int N=1e7+5;
const int T=3e6+5;
const int m=1e9+7;
ll te,n,a,b,c;
ll d[N],t[N],p[N],prime[N],g[N],f[N];
ll query[T];
ll ansd,anssum;
inline void solve()
{
d[1]=1,t[1]=1,f[1]=1;
for (ll i=2;i<=n;++i)
{
if (!p[i])
{
d[i]=2,t[i]=1;f[i]=(i*i+1)%m,g[i]=1;
prime[++prime[0]]=i;
}
for (ll j=1;j<=prime[0]&&i*prime[j]<=n;++j)
{
p[i*prime[j]]=1;
if (i%prime[j]==0)
{
t[i*prime[j]]=(t[i]+1)%m;
d[i*prime[j]]=(d[i]/(t[i]+1)*(t[i*prime[j]]+1))%m;
g[i*prime[j]]=g[i]%m;
f[i*prime[j]]=(f[i]*prime[j]*prime[j]%m+f[g[i]])%m;
break;
}
else {
d[i*prime[j]]=d[i]*2%m;
t[i*prime[j]]=1;
g[i*prime[j]]=i%m;
f[i*prime[j]]=(f[i]*prime[j]*prime[j]%m+f[i])%m;
}
}
}
}
int main()
{
scanf("%lld%lld%lld%lld%lld",&te,&n,&a,&b,&c);
query[1]=n;
for (ll i=2;i<=te;++i){
query[i]=(query[i-1]*a%c+b)%c+1;
n=max(n,query[i]);
}
solve();
ansd=anssum=0;
for (ll i=1;i<=te;++i){
ansd=(ansd+d[query[i]])%m;
if (query[i]%2) ansd=(ansd+1)%m;
anssum=(anssum+f[query[i]])%m;
if (query[i]%2) anssum=(anssum+4)%m;
}
printf("%lld\n",ansd);
printf("%lld\n",anssum);
}