exp

Description
请计算 n mod 1 + n mod 2 +…+ n mod n 的值。
Input
只包含一个正整数 n。
Output
只包含一个整数,为问题描述中所求表达式的值。
Sample Input
5
Sample Output
4


【样例说明】


5 mod 1 + 5 mod 2 + 5 mod 3 + 5 mod 4 + 5 mod 5 = 0 + 1 + 2 + 1 + 0 = 4。
Data Constraint
对于 60%的数据满足:1 ≤ n ≤ 5,000;

对于 100%的数据满足:1 ≤ n ≤ 1,000,000,000。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long b,ans,last,last1,i,j,k,last2;
int a,c;
int main()
{
	freopen("exp.in","r",stdin);
	freopen("exp.out","w",stdout);
	scanf("%d",&a);
	b=trunc(sqrt(a));
	for (c=1;c<=b;c++)
	{
		ans+=a%c;
	}
	last=a;
	while (last!=b) 
	{
		last1+=1;
		i=(a/(last1+1))+1;
		j=a%last1;
		k=last-i+1;
		last2=j+(k-1)*last1;
		ans+=(last2+j)*k/2;
		last=i-1;
	}
	printf("%lld",ans);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值