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

高效求解区间约数

时间:2018-08-29 10:42:22      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:scanf   pac   for   while   div   +=   temp   space   高效   

#include<cstdio>
using namespace std;
 
typedef long long LL;
LL ac(int n)
{
    LL ans=0;
    for(int i=1,temp;i<=n;i=temp+1)
    {
        temp=n/(n/i);
        ans+=(n/i)*(temp-i+1);
    }
    return ans;
}
 
int main ()
{
    int n,t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        printf("%lld\n",ac(n));
    }

    return 0;
}

 

高效求解区间约数

标签:scanf   pac   for   while   div   +=   temp   space   高效   

原文地址:https://www.cnblogs.com/Yinchen-One/p/9552122.html

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