The number of divisors(约数) about Humble Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1947 Accepted Submission(s): 959
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.
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
Author
lcy
Source
Recommend
LL
题意简述: 由质数2,3,5,7相乘(每个数的数目不限)所得到的数,称为“humble number”,该题给定一个humble number,求它一共有多少约数?
解题思路:先求出该数在只用2,3,5,7表示时2,3,5,7的数目,分别用b[0],b[1],b[2],b[3]表示,然后(b[0]+1)*(b[1]+1)*(b[2]+1)*(b[3]+1)即为所求该数约数的个数!为什么呢?数学中的组合问题,分步来做!第一步,从b[0]个2中选择若干个2,可以是,0,1,2,,,b[0]个,总共b[0]+1种情况,然后从b[1]个3中,选择若干个3,以此类推。。。
View Code
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 int main() 4 { 5 int b[4], i, cnt; 6 __int64 n, a[4] = {2,3,5,7}; 7 while( (scanf("%I64d",&n)!=EOF) && n ) 8 { 9 cnt = 1; 10 memset(b,0,sizeof(b)); 11 for( i = 0; i < 4; i++ ) 12 while( !(n % a[i]) ) 13 { 14 b[i]++; 15 n = n / a[i]; 16 } 17 for( i = 0; i < 4; i++ ) 18 cnt *= (b[i] + 1); 19 printf( "%d\n", cnt ); 20 } 21 return 0; 22 }