The number of divisors(约数) about Humble Numbers(有多少因数)

来源:互联网 发布:淘宝买qq号怎么搜 编辑:程序博客网 时间:2024/04/28 08:29

The number of divisors(约数) about Humble Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2862    Accepted Submission(s): 1390


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
4120
 

Sample Output
36
题意:求N有多少个因数,其中N的质因数值有2,5,7,3,求出每个质因数的个数 每个个数加1(每一个基础因数都可能不存在),再相乘就是答案,

知道基础的因数,再求有多少种组合方法,实在不懂可以用 4层for循环构造组合方法。

     int cou=0;     for(int i=0;i<=s2;i++)     {          for(int j=0;j<=s3;j++)          {                  for(int k=0;k<=s5;k++)                  {                          for(int p=0;p<=s7;p++)                          {                                  cou++;                          }                  }          }     }
其实就是相乘!!!

code:

#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;const int k=9973;int prim[10005];int a[33000];__int64 n,ans;__int64 s2,s3,s5,s7;int main(){    int t,i,j,ans;    while(scanf("%lld",&n),n)    {        s2=s3=s5=s7=0;        while(n%2==0 && n){            s2++;            n/=2;        }        while(n%3==0 && n){            s3++;            n/=3;        }        while(n%5==0 && n){            s5++;            n/=5;        }        while(n%7==0 && n){            s7++;            n/=7;        }        s2++;s5++;s7++;s3++;    cout<<s2*s5*s7*s3<<endl;    }    return 0;}
数学是神造的科学!!!

0 0