高效求解区间约数

#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
",ac(n));
    }

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