“謙虛數(shù)”數(shù)論因數(shù)

The number of divisors(約數(shù)) 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

這么簡(jiǎn)單的題目沒(méi)有一次AC真的是天理難容啊!!
看了網(wǎng)上的代碼才知道了原來(lái)是題意理解不清楚,以后要多加注意。
本題屬于數(shù)學(xué)問(wèn)題:
一個(gè)數(shù),如果所有的因數(shù)都是2,3,5,7,那么這個(gè)數(shù)被稱為謙虛數(shù),輸入一個(gè)謙虛數(shù),打印該數(shù)的合法因數(shù)數(shù)量。
需要注意的是,這里輸入的對(duì)象是一個(gè)謙虛數(shù),那么只要將該謙虛數(shù)不斷除以2,3,5,7,每除一次,參數(shù)加一,將所有素質(zhì)數(shù)求積,最后輸出即可。
代碼為:

#include <stdio.h>
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);
    }
}

至于涉及到的數(shù)論知識(shí),則是在于最后解的輸出,(所有素質(zhì)數(shù)相乘)。例如:a個(gè)2為因數(shù),那么這a個(gè)2會(huì)分成多種情況:1個(gè)2乘(a-1)個(gè)2,2個(gè)2乘(a-2)個(gè)2,3個(gè)2乘(a-3)個(gè)2……(a/2)個(gè)2乘(a-2)個(gè)2,總結(jié)起來(lái),恰巧有a種情況,故乘積。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,921評(píng)論 0 23
  • 背景 一年多以前我在知乎上答了有關(guān)LeetCode的問(wèn)題, 分享了一些自己做題目的經(jīng)驗(yàn)。 張土汪:刷leetcod...
    土汪閱讀 12,775評(píng)論 0 33
  • 多多大將軍閱讀 384評(píng)論 1 7
  • 九月一到,就有了秋意,秋意在一個(gè)多霧的黎明溜來(lái),到了炎熱的下午便不見(jiàn)蹤影。它踮起腳尖掠過(guò)樹(shù)頂,染紅幾片葉子,然后乘...
    飄姐閱讀 347評(píng)論 1 1
  • 我處在暴躁的邊緣 大腦走來(lái)走去,無(wú)處安置 我處在疲態(tài)的邊緣 大腦轉(zhuǎn)來(lái)轉(zhuǎn)去,無(wú)法停息 我處在消失的邊緣 大腦空白無(wú)物...
    呆子Y默閱讀 124評(píng)論 0 0