题面:
题解:
考虑因子x在1–n中出现的次数为n/x
枚举因子,数论分块。
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<list>
#include<iterator>
#define ll long long
#define llu unsigned ll
#define iu unsigned int
#define ld long double
//#define int ll
using namespace std;
const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
const double dnf=1e15;
const double eps=1e-8;
const double pi=acos(-1.0);
const int mod=1e9+7;
const int maxn=210;
int main(void)
{
int n;
int ans=0;
scanf("%d",&n);
for(int l=1,r;l<=n;l=r+1)
{
r=n/(n/l);
ans+=(n/l)*(r-l+1);
}
printf("%d\n",ans);
return 0;
}