zoukankan      html  css  js  c++  java
  • HDU1492The 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相乘即可

     1 #include<stdio.h>
     2 #include<iostream>
     3 #include<string.h>
     4 using namespace std;
     5 typedef long long ll;
     6 
     7 //ll n;
     8 //
     9 //ll prime()
    10 //{
    11 //    ll ans=0;
    12 //    for(ll i=1;i<=n;i++)
    13 //    {
    14 //        if(n%i==0)
    15 //            ans++;
    16 //    }
    17 //    return ans;
    18 //}
    19 
    20 int mark[4];
    21 int main()
    22 {
    23     ll n;
    24     while(~scanf("%lld",&n)&&n)
    25     {
    26 //        printf("%lld\n",prime());
    27         memset(mark,0,sizeof(mark));//每个数字的指数
    28         while(n&&n%2==0)
    29         {
    30             mark[0]++;
    31             n=n/2;
    32 //            cout<<n<<endl;
    33         }
    34 //        cout<<"***"<<mark[0]<<endl;
    35         while(n&&n%3==0)
    36         {
    37             mark[1]++;
    38             n=n/3;
    39         }
    40         while(n&&n%5==0)
    41         {
    42             mark[2]++;
    43             n=n/5;
    44         }
    45         while(n&&n%7==0)
    46         {
    47             mark[3]++;
    48             n=n/7;
    49         }
    50         cout<<(1+mark[0])*(1+mark[1])*(1+mark[2])*(1+mark[3])<<endl;
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    git 学习
    公司领导写给新员工的信
    PLSQl远程连接oracle数据库
    hdu2222之AC自动机入门
    代码中添加事务控制 VS(数据库存储过程+事务) 保证数据的完整性与一致性
    ubuntu13.04安装SenchaArchitect-2.2无法启动的问题
    MVVMLight Toolkit在Windows Phone中的使用扩展之一:在ViewModel中实现导航,并传递参数
    面试题24:二叉搜索树与双向链表
    Struts2中的包的作用描述
    filter-mapping中的dispatcher使用
  • 原文地址:https://www.cnblogs.com/OFSHK/p/11342683.html
Copyright © 2011-2022 走看看