bzoj1968 [Ahoi2005]COMMON 约数研究

1968: [Ahoi2005]COMMON 约数研究

Time Limit: 1 Sec  Memory Limit: 64 MB

Description

Input

只有一行一个整数 N(0 < N < 1000000)。

Output

只有一行输出,为整数M,即f(1)到f(N)的累加和。

Sample Input

3

Sample Output

5
 
 
 
Tip:
  这是一道思维题,想到后就会觉得很简单;
  请先思考思考;
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  。
  我们可以知道F[x]=n/x;
  约数中有x的数有n整除x个,我们只要线扫一遍就能得出答案;
 
Code:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
    long long n,res=0,a,b;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        res+=n/i;
    }
    printf("%lld",res);
}
  
原文地址:https://www.cnblogs.com/WQHui/p/7475736.html