# 题面

$n\le10^{10}$

# CODE

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 200005;
const int mod = 1e9 + 7;
const int inv2 = 5e8 + 4;
int n, sqr, m, a[N], f[N], s[2][N];
inline int ID(int x) { return x <= sqr ? x : m-n/x+1; }
signed main () {
scanf("%lld", &n), sqr = sqrt(n), m = 0;
for(int i = 1; i <= n; ++i)
a[++m] = i = n/(n/i),
s[0][m] = (i-1) % mod,
s[1][m] = ((i%mod) * ((i+1)%mod) % mod * inv2 % mod - 1) % mod;
for(int i = 2; i <= sqr; ++i) if(s[0][i] > s[0][i-1])
for(int j = m; a[j] >= i*i; --j)
(s[0][j] -= s[0][ID(a[j]/i)]-s[0][i-1]) %= mod,
(s[1][j] -= i*(s[1][ID(a[j]/i)]-s[1][i-1])) %= mod;
for(int i = 2; i <= m; ++i) f[i] = (s[1][i]-s[0][i]+2) % mod; //加一个2
for(int i = sqr; i > 1; --i) if(s[0][i] > s[0][i-1])
for(int j = m; a[j] >= i*i; --j)
for(int k = 1, pw = i, sp = (s[1][i]-s[0][i]+2)%mod; pw*i <= a[j]; ++k, pw *= i)
(f[j] += (i^k)*(f[ID(a[j]/pw)]-sp)+(i^(k+1))) %= mod;
printf("%lld\n", (f[m]+1+mod)%mod);
}



©️2019 CSDN 皮肤主题: 精致技术 设计师: CSDN官方博客