51nod1225 余数之和

打表可以看出规律。分块求就可以了。

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define ll long long
ll read(){
	ll x=0;char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
	return x;
}
const ll mod=1e9+7;
const ll tt=5e8+4;
int main(){
	ll n=read(),last,ans=0;
	for(ll i=1;i<=n;i=last+1){
		last=n/(n/i);
		ans=(ans+(last-i+1)%mod*((n%i+n%last)%mod)%mod*tt%mod)%mod;
	}
	printf("%lld
",ans);
	return 0;
}

  

基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题
 收藏
 关注
F(n) = (n % 1) + (n % 2) + (n % 3) + ...... (n % n)。其中%表示Mod,也就是余数。 
例如F(6) = 6 % 1 + 6 % 2 + 6 % 3 + 6 % 4 + 6 % 5 + 6 % 6 = 0 + 0 + 0 + 2 + 1 + 0 = 3。
给出n,计算F(n), 由于结果很大,输出Mod 1000000007的结果即可。
 
Input
输入1个数N(2 <= N <= 10^12)。
Output
输出F(n) Mod 1000000007的结果。
Input示例
6
Output示例
3
原文地址:https://www.cnblogs.com/fighting-to-the-end/p/5868347.html