3729. 【NOIP2014模拟7.10】表达式的值(exp) (File IO): input:exp.in output:exp.out
Time Limits:
1000 ms Memory Limits:
524288 KB Detailed Limits
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);
}
转载请注明原文地址: https://ju.6miu.com/read-5712.html