BZOJ1968_COMMON约数研究_KEY

题目传送门

BZOJ水题,for i=1~N,答案加上N/i即可

ANS=∑N/i(i∈{1~N})

code:

/**************************************************************
    Problem: 1968
    User: yekehe
    Language: C++
    Result: Accepted
    Time:32 ms
    Memory:10588 kb
****************************************************************/
 
#include <cstdio>
using namespace std;
 
char tc()
{
    static char fl[10000000],*A=fl,*B=fl;
    return A==B&&(B=(A=fl)+fread(fl,1,10000000,stdin),A==B)?EOF:*A++;
}
 
int read()
{
    char c;while(c=getchar(),(c<'0'||c>'9')&&c!='-');int x=0,y=1;c=='-'?y=-1:x=c-'0';
    while(c=getchar(),c>='0'&&c<='9')x=x*10+c-'0';return x*y;
     
}
 
int N,ans;
 
int main()
{
    N=read();
        for(int i=1;i<=N;i++)ans+=N/i;
    printf("%d",ans);
    return 0;
}

 

posted @ 2018-01-07 19:56  Cptraser  阅读(112)  评论(1编辑  收藏  举报