hdu 1492

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1492

题意:丑数(humble number)是一种素因子只有2、3、5、7组成的数字。给一个丑数,问它有多少因数。

mark:基础数论。因为只有2、3、5、7四种素因子,因此只要求出幂次,加1后乘起来就好了。注意要用long long。

代码:

# include <stdio.h>


long long div(long long x, int b)
{
    int rtn = 0 ;
    while (x%b==0)
    {
        x /= b ;
        rtn ++ ;
    }
    return rtn ;
}


int main ()
{
    long long n, mul ; 
    while (~scanf ("%I64d", &n),n)
    {
        mul = 1 ;
        mul *= (div(n,2)+1) ;
        mul *= (div(n,3)+1) ;
        mul *= (div(n,5)+1) ;
        mul *= (div(n,7)+1) ;
        printf ("%I64d\n", mul) ;
    }
    return 0 ;
}
posted @ 2012-04-11 01:47  Seraph2012  阅读(377)  评论(0编辑  收藏  举报