长记性:1.除化乘逆元 2.每一步都取模 3.注意+mod
1 #include <bits/stdc++.h> 2 #include <ctime> 3 #include <algorithm> 4 #include <random> 5 using namespace std; 6 typedef long long ll; 7 typedef unsigned long long ull; 8 const int maxn = 2e4+10; 9 const int mod = 1e9+7; 10 const int inf = 0x3f3f3f3f; 11 #define gok ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) 12 #define pii pair<int,int> 13 #define fi first 14 #define se second 15 #define pb push_back 16 #define rep(i,first,second) for(int i=first;i<=second;i++) 17 #define dep(i,first,second) for(int i=first;i>=second;i--) 18 #define erep(i,u) for(int i=head[u];~i;i=e[i].nxt) 19 20 ll n,ans,inv; 21 int main() 22 { 23 scanf("%lld",&n); 24 ans = (n%mod)*(n%mod)%mod; 25 inv=5e8+4; 26 27 for(ll l=1ll,r;l<=n;l=r+1ll){ 28 r=min(n/(n/l),n); 29 ans = (ans+(mod-((((n/l)%mod*(l+r)%mod)%mod*((r-l+1)%mod))%mod*(inv%mod))%mod)%mod)%mod; 30 } 31 printf("%lld ",ans); 32 return 0; 33 }