zoukankan      html  css  js  c++  java
  • HDU1492/The number of divisors(约数) about Humble Numbers

    题目连接


    The number of divisors(约数) about Humble Numbers

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

    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

    Author
    lcy

    Source
    “2006校园文化活动月”之“校庆杯”大学生程序设计竞赛暨杭州电子科技大学第四届大学生程序设计竞赛

    /*
    求一个数的约数:x=p1^x1 * p2^x2 * p3^x3.....
    p1p2p3分别为素数,那么x的约数的个数就是ans=(x1+1)*(x2+1)*(x2+1)....
    */
    #include <set>
    #include <map>
    #include <cmath>
    #include <queue>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    typedef long long  LL;
    using namespace std;
    int a[6]={2,3,5,7};
    int main ()
    {
        LL n;
        while(scanf("%lld",&n),n)
        {
            LL ans=1;
            int i=0;
            int t=0;
            while(n)
            {
                if(n%a[i]==0)
                {
                    t++;
                    n/=a[i];
                }
                else
                {
                    ans*=(t+1);
                    t=0;
                    i++;
                    if(n==1)
                        break;
                }
    
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
    想的太多,做的太少。
  • 相关阅读:
    CSS3美化网页元素
    表单
    列表,表格与媒体元素
    HTML5基础
    双列集合map-1
    单列集合List
    kafka-Eagle的安装
    kafka-自定义拦截器(interceptor)
    kafka-Consumer API
    kafka-Producer API
  • 原文地址:https://www.cnblogs.com/pealicx/p/6115598.html
Copyright © 2011-2022 走看看