1. 程式人生 > >Newcoder 39 A.約數個數的和(水~)

Newcoder 39 A.約數個數的和(水~)

Description

給個 n n ,求 1 1 n n

的所有數的約數個數的和~

Input

第一行一個正整數 n n

( 1 n

1 0 8 ) (1\le n\le 10^8)

Output

輸出一個整數,表示答案

Sample Input

3

Sample Output

5

Solution

a

n s = i = 1 n n i ans=\sum\limits_{i=1}^n\lfloor\frac{n}{i}\rfloor ,分塊加速或者直接求都行

Code

#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	scanf("%d",&n);
	ll ans=0;
	for(int i=1,pre;i<=n;i=pre+1)
	{
		pre=n/(n/i);
		ans+=1ll*(n/i)*(pre-i+1);
	}
	printf("%lld\n",ans);
	return 0;
}