The first question is just to play with you...only 1 when i=1, 0 otherwise, so the prefix sum is always 1.
Consider the second question.
therefore
Or use Du Jiaosi's routine:
For this f, what g should we choose, considering we want to calculate
Bundle
We find it very good to let g(x)=x, so that we get
So we get
Forget it.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 1000010
#define mod 1000000007
inline char gc(){
static char buf[1<<16],*S,*T;
if(S==T){T=(S=buf)+fread(buf,1,1<<16,stdin);if(T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0,f=1;char ch=gc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc();
return x*f;
}
int n,prime[N>>3],tot=0,inv6;ll phi[N],s[10000];
bool notprime[N];
inline int ksm(int x,int k){
int res=1;for(;k;k>>=1,x=(ll)x*x%mod) if(k&1) res=(ll)res*x%mod;return res;
}
inline void init(){
notprime[1]=1;phi[1]=1;
for(int i=2;i<=1e6;++i){
if(!notprime[i]) prime[++tot]=i,phi[i]=i-1;
for(int j=1;prime[j]*i<=1e6;++j){
notprime[prime[j]*i]=1;
if(i%prime[j]==0){
phi[prime[j]*i]=phi[i]*prime[j];break;
}phi[prime[j]*i]=phi[i]*phi[prime[j]];
}
}for(int i=2;i<=1e6;++i) phi[i]=(phi[i]*i+phi[i-1])%mod;
}
inline ll calc(int x){
if(x<=1e6) return phi[x];
if(s[n/x]) return s[n/x];
ll res=(ll)x*(x+1)%mod*(2*x+1)%mod*inv6%mod;
for(int i=2,last;i<=x;i=last+1){
last=x/(x/i);
res-=((ll)last+i)*(last-i+1)/2%mod*calc(x/i)%mod,res%=mod;
}return s[n/x]=res<0?res+mod:res;
}
int main(){
// freopen("a.in","r",stdin);
n=read();init();puts("1");inv6=ksm(6,mod-2);
printf("%lld\n",calc(n));
return 0;
}