“谦虚数”数论因数

The number of divisors(约数) about Humble Numbers
Problem Description

A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers.

Now given a humble number, please write a program to calculate the number of divisors about this humble number.For examle, 4 is a humble,and it have 3 divisors(1,2,4);12 have 6 divisors.

Input

The input consists of multiple test cases. Each test case consists of one humble number n,and n is in the range of 64-bits signed integer. Input is terminated by a value of zero for n.

Output

For each test case, output its divisor number, one line per case.

Sample Input

4
12
0

Sample Output

3
6

这么简单的题目没有一次AC真的是天理难容啊!!
看了网上的代码才知道了原来是题意理解不清楚,以后要多加注意。
本题属于数学问题:
一个数,如果所有的因数都是2,3,5,7,那么这个数被称为谦虚数,输入一个谦虚数,打印该数的合法因数数量。
需要注意的是,这里输入的对象是一个谦虚数,那么只要将该谦虚数不断除以2,3,5,7,每除一次,参数加一,将所有素质数求积,最后输出即可。
代码为:

#include 
void main()
{
    int a,b,c,d;
    __int64 n,i,m;
    while(scanf("%I64d",&n)!=EOF&&n!=0)
    {
        a=b=c=d=1;
        while(n!=1)
        {
            while(n%2==0)
            {
                n=n/2;
                a++;
            }
            while(n%3==0)
            {
                n=n/3;
                b++;
            }
            while (n%5==0)
            {
                n=n/5;
                c++;
            }
            while (n%7==0)
            {
                n=n/7;
                d++;
            }
        }
        printf("%d\n",a*b*c*d);
    }
}

至于涉及到的数论知识,则是在于最后解的输出,(所有素质数相乘)。例如:a个2为因数,那么这a个2会分成多种情况:1个2乘(a-1)个2,2个2乘(a-2)个2,3个2乘(a-3)个2……(a/2)个2乘(a-2)个2,总结起来,恰巧有a种情况,故乘积。

你可能感兴趣的:(“谦虚数”数论因数)