高效求解区间约数

#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;
}

 

posted @ 2018-08-29 08:33  奋斗の小白  阅读(284)  评论(0编辑  收藏  举报