zoukankan      html  css  js  c++  java
  • hdu 1492(约数的个数)

    The number of divisors(约数) about Humble Numbers

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


    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
     
    如果n = p1a1p2a2p3a3...pnan 那么根据乘法原理,约数的个数为 (a1+1)*(a2+1)...(an+1)
    #include <stdio.h>
    #include <math.h>
    #include <iostream>
    #include <algorithm>
    #include <string.h>
    #include <stdlib.h>
    using namespace std;
    typedef long long LL;
    
    int main()
    {
        LL n;
        while(scanf("%lld",&n)!=EOF,n)
        {
            int cnt = 0;
            int a=0,b=0,c=0,d=0;
            if(n%2==0)
            {
                while(n%2==0)
                {
                    n/=2;
                    a++;
                }
            }
            if(n%3==0)
            {
                while(n%3==0)
                {
                    n/=3;
                    b++;
                }
            }
            if(n%5==0)
            {
                while(n%5==0)
                {
                    n/=5;
                    c++;
                }
            }
            while(n%7==0)
            {
                while(n%7==0)
                {
                    n/=7;
                    d++;
                }
            }
            printf("%lld
    ",(LL)(1+a)*(1+b)*(1+c)*(1+d));
        }
    }
  • 相关阅读:
    【Rollo的Python之路】Python 编码与解码
    【Rollo的Python之路】Python 队列 学习笔记 queue
    【Rollo的Python之路】Python 同步条件 学习笔记 Event
    【Rollo的Python之路】Python 条件变量同步 学习笔记 Condition
    【Rollo的Python之路】Python 信号量 学习笔记 Semaphore
    十天冲刺-09
    十天冲刺-08
    十天冲刺-07
    十天冲刺-06
    十天冲刺-05
  • 原文地址:https://www.cnblogs.com/liyinggang/p/5520597.html
Copyright © 2011-2022 走看看