码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 11526 H(n)

时间:2017-08-21 21:32:54      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:read   getc   tchar   font   size   tps   style   class   ref   

https://cn.vjudge.net/problem/UVA-11526

 

除法分块

 

#include<cstdio>
#include<iostream>
using namespace std;
typedef long long LL;
void read(long long &x)
{
    x=0; char c=getchar(); int f=1;
    while(!isdigit(c)) { if(c==-) f=-1; c=getchar();}
    while(isdigit(c)) { x=x*10+c-0; c=getchar(); }
    x*=f;
}
int main()
{
    int T;
    LL n,ans;
    scanf("%d",&T);
    while(T--)
    {
        read(n);
        ans=0;
        LL i=1,j;
        while(i<=n)
        {
            j=n/(n/i);
            ans+=(j-i+1)*(n/i);
            i=j+1;
        }
        printf("%lld\n",ans);
    }
}

 

UVA 11526 H(n)

标签:read   getc   tchar   font   size   tps   style   class   ref   

原文地址:http://www.cnblogs.com/TheRoadToTheGold/p/7406712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!