您的位置:首页 > 其它

The number of divisors(约数) about Humble Numbers

2013-04-21 21:57 344 查看

The number of divisors(约数) about Humble Numbers

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1887 Accepted Submission(s): 925



[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
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.

[align=left]Output[/align]
For each test case, output its divisor number, one line per case.

[align=left]Sample Input[/align]

4
12
0


[align=left]Sample Output[/align]

3
6


[align=left]Author[/align]
lcy

思路:
如果一个数n有质因子a,b,c...
n=a^a1*b^b1.....
则约数个数有
(a1+1)*(b1+1).....

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
__int64 n;
while(scanf("%I64d",&n)&&n!=0){
__int64 a[4];
memset(a,0,sizeof(a));
int i=0;
while(n%2==0){
n=n/2;
a[i]++;
}
i++;
while(n%3==0){
n/=3;
a[i]++;
}
i++;
while(n%5==0){
n/=5;
a[i]++;
}
i++;
while(n%7==0){
n/=7;
a[i]++;
}

__int64 sum=1;
for(i=0;i<4;i++)
sum*=(a[i]+1);
printf("%I64d\n",sum);

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: