#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
//#include<ctime>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
const int maxn = 5E6 + 50;
typedef long long LL;
const LL Mod = 999987;
const LL mo = 1000000007;
struct data{
LL Num; int ret; data(){}
data(LL Num,int ret): Num(Num),ret(ret){}
};
int tot,Ans,Inv_2,Inv_6,phi[maxn],pri[maxn];
bool not_pri[maxn]; LL n;
vector <data> v[Mod];
int Mul(const LL &x,const LL &y) {return x * y % mo;}
int Add(const int &x,const int &y) {return x + y < mo ? x + y : x + y - mo;}
int Dec(const int &x,const int &y) {return x - y < 0 ? x - y + mo : x - y;}
int ksm(int x,int y)
{
int ret = 1;
for (; y; y >>= 1)
{
if (y & 1) ret = Mul(ret,x);
x = Mul(x,x);
}
return ret;
}
int Sum_2(LL N)
{
int A = Mul(N % mo,(1LL + N) % mo);
int B = Mul(2LL * N % mo + 1LL,Inv_6);
return Mul(A,B);
}
int Sum_3(LL N)
{
int A = Mul((1LL + N) % mo,Inv_2);
A = Mul(A,N % mo); return Mul(A,A);
}
int Search(LL N)
{
int pos = N % Mod;
for (int i = 0; i < v[pos].size(); i++)
if (v[pos][i].Num == N) return v[pos][i].ret;
return -1;
}
void Insert(LL N,int now)
{
int pos = N % Mod;
v[pos].push_back(data(N,now));
}
int Calc(LL N)
{
if (N < maxn) return phi[N];
LL ret = Search(N);
if (ret != -1) return ret; ret = Sum_3(N);
for (LL i = 2,last; i <= N; i = last + 1LL)
{
last = N / (N / i);
int now = Calc(N / i);
int sum = Dec(Sum_2(last),Sum_2(i - 1LL));
ret = Dec(ret,Mul(now,sum));
}
Insert(N,ret); return ret;
}
int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif
cin >> n; phi[1] = 1;
for (int i = 2; i < maxn; i++)
{
if (!not_pri[i])
pri[++tot] = i,phi[i] = i - 1;
for (int j = 1; j <= tot; j++)
{
LL Nex = 1LL * i * pri[j];
if (Nex >= maxn) break;
not_pri[Nex] = 1;
if (i % pri[j] == 0)
{
phi[Nex] = phi[i] * pri[j];
break;
}
phi[Nex] = phi[i] * phi[pri[j]];
}
}
//cerr << (double)(clock()) / CLOCKS_PER_SEC << endl;
for (int i = 2; i < maxn; i++)
{
phi[i] = Mul(phi[i],Mul(i,i));
phi[i] = Add(phi[i],phi[i - 1]);
}
//cerr << (double)(clock()) / CLOCKS_PER_SEC << endl;
Inv_2 = ksm(2,mo - 2); Inv_6 = ksm(6,mo - 2);
for (LL i = 1,last; i <= n; i = last + 1LL)
{
last = n / (n / i);
int ret = Calc(n / i);
int B = Mul(Inv_2,Mul((i + last) % mo,(last - i + 1LL) % mo));
Ans = Add(Ans,Mul(ret,B));
}
cout << Ans << endl;
//cerr << (double)(clock()) / CLOCKS_PER_SEC << endl;
return 0;
}
51NOD1238
最新推荐文章于 2019-02-28 09:06:00 发布