[Ahoi2005]COMMON 约数研究
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 4304 Solved: 2907
[Submit][Status][Discuss]
Description
Input
只有一行一个整数 N(0 < N < 1000000)。
Output
只有一行输出,为整数M,即f(1)到f(N)的累加和。
Sample Input
3
Sample Output
5
题解
我们可以知道对于一个数只会对他的和他的倍数做贡献,所以我们计算1-n每个因子的贡献度就行了。
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<int> g;
set<int> st;
signed main()
{
int n; scanf("%lld",&n);
int res=0;
for(int i=1;i<=n;i++) res+=n/i;
printf("%lld\n",res);
}