HDU-1492-The number of divisors(约数) about Humble Numbers -求因子总数+唯一分解定理的变形

时间:2023-03-09 20:02:51
HDU-1492-The number of divisors(约数) about Humble Numbers -求因子总数+唯一分解定理的变形
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.

InputThe 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. 
OutputFor each test case, output its divisor number, one line per case. 
Sample Input

4
12
0

Sample Output

3
6

题意:给出一个丑数n,这个数必定可以分解成多个2、3、5、7的形式

求:n的因子数

思路:唯一分解定理求因子个数,唯一不同的是唯一分解定理需要记录每个质数的指数,而该题则已经确定是2、3、5、7了,所以只要对这四个数进行计算指数再相互之间+1相乘即可

 #include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
typedef long long ll; //ll n;
//
//ll prime()
//{
// ll ans=0;
// for(ll i=1;i<=n;i++)
// {
// if(n%i==0)
// ans++;
// }
// return ans;
//} int mark[];
int main()
{
ll n;
while(~scanf("%lld",&n)&&n)
{
// printf("%lld\n",prime());
memset(mark,,sizeof(mark));//每个数字的指数
while(n&&n%==)
{
mark[]++;
n=n/;
// cout<<n<<endl;
}
// cout<<"***"<<mark[0]<<endl;
while(n&&n%==)
{
mark[]++;
n=n/;
}
while(n&&n%==)
{
mark[]++;
n=n/;
}
while(n&&n%==)
{
mark[]++;
n=n/;
}
cout<<(+mark[])*(+mark[])*(+mark[])*(+mark[])<<endl;
}
return ;
}