Number of Containers [ZOJ 3126]

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3216

View Code
//复杂度O(sqrt(N)),蛮有意思的
const int MM = 11111;
typedef long long int64;
int64 N;
void solve() {
    int64 i,j,k,sum=0,tmp;
    scanf("%lld",&N);
    for(i=1;(i*i)<=N;i++) {
        tmp=N/i;
        sum=sum+i*(N/i-N/(i+1));
        if(tmp!=i) sum=sum+tmp*(N/tmp-N/(tmp+1));
    }
    printf("%lld\n",sum-N);
}

 

posted @ 2013-05-07 20:53  zhang1107  阅读(131)  评论(0编辑  收藏  举报