https://ac.nowcoder.com/acm/contest/1114/B
这题时间卡的比较死,多了一个快速幂的logn就过不了这题。
#include<bits/stdc++.h> using namespace std; #define ll long long const int p=1e9+7; const int N=3e6+10; ll power[N]; int main() { int n; cin>>n; ll ans=0; for(int i=0;i<=N-5;i++) { power[i]=i; } for(int j=1;j<=n;j++) { int i; for( i=j;i+j-1<=n;i=i+j) { ll x=i/j; ans=(ans+1ll*(i+j+i-1)*(j)/2%p*power[x]%p)%p; power[x]=(power[x]*x)%p; } if(i<=n) { ll x=i/j; ans=(ans+(1ll)*(n+i)*(n-i+1)/2%p*power[n/i]%p)%p; power[x]=power[x]*x%p; } } cout<<ans<<" "; return 0; }