求一个数的因子数以及因子和

求因子数:

LL Getn(LL x){
    LL ret = 1;
    for(LL i = 2; i * i <= x; i++){
        if(x % i == 0){
            LL a = 0;
            while(x % i == 0){
                x /= i;
                a++;
            }
            ret = ret * (a + 1);
        }
    }
    if(x > 1){
        ret *= 2;
    }
    return ret;
}

求因子和:

int sum(int n){
    int s=1;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            int a=1;
            while(n%i==0){
                n/=i;
                a*=i;
            }
            s=s*(a*i-1)/(i-1);
        }
    }
    if(n>1) s=s*(1+n);
    return s;
}
原文地址:https://www.cnblogs.com/-Ackerman/p/12274467.html