“谦虚数”数论因数

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 <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);
    }
}

至于涉及到的数论知识,则是在于最后解的输出,(所有素质数相乘)。例如: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种情况,故乘积。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,878评论 0 23
  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 12,769评论 0 33
  • 多多大将军阅读 384评论 1 7
  • 九月一到,就有了秋意,秋意在一个多雾的黎明溜来,到了炎热的下午便不见踪影。它踮起脚尖掠过树顶,染红几片叶子,然后乘...
    飘姐阅读 347评论 1 1
  • 我处在暴躁的边缘 大脑走来走去,无处安置 我处在疲态的边缘 大脑转来转去,无法停息 我处在消失的边缘 大脑空白无物...
    呆子Y默阅读 124评论 0 0