求一个数的正数因子(模板)

转:文章

int f(int x)
{
    int sum=1,cnt;
    for(int i=2;i*i<=x;i++)
    {
        cnt=0;
        while(x%i==0)
        {
            x/=i;
            cnt++;
        }
        sum*=(cnt+1);
    }
    if(x>1) sum*=2;
    return sum;
}

猜你喜欢

转载自www.cnblogs.com/2018zxy/p/10178598.html