题解 [51nod1225]余数之和
题解 [51nod1225]余数之和
题面
解析
首先可以发现,\(a\)%\(b\)\(=a-b*\lfloor a/b \rfloor\).
而对于一段连续的\(b\)来说\(\lfloor a/b\rfloor\)是一样的.
并且这一段\(b\)是等差数列.
因此整除分块搞一搞就行了.
数据范围真的恶心(爆longlong)
code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define int __int128
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;
inline int read(){
int sum=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
return f*sum;
}
const int Mod=1000000007;
int n,ans;
inline int fpow(int a,int b){
int ret=1;
for(;b;a=a*a%Mod,b>>=1) if(b&1) ret=ret*a%Mod;
return ret;
}
signed main(){
n=read();int inv=fpow(2,Mod-2);
for(int l=1,r;l<=n;l=r+1){
r=n/(n/l);
ans=(ans+(n/l)*inv%Mod*(l+r)%Mod*(r-l+1)%Mod)%Mod;
}
ans=((n%Mod)*(n%Mod)-ans)%Mod;
long long ret=(ans+Mod)%Mod;
printf("%lld\n",ret);
return 0;
}