原题链接

题目大意:定义了一种数字Humble Number,他们的质因数只包含2、3、5、7中的一个或者几个,求第n个这样的数,1<=n<=5842.

解法:一看到这道题又在想DFS了,可是我写的不熟练,最后罢工。Google之,发现还是可以用穷举法解决的。先列出2000000000以内的所有Humble Number,然后再查表。输出的时候要注意下,尾数是1、2、3的和剩下的数字要区别对待,可是尾数是11、12、13又是不一样的。

参考代码:

#include<iostream>
#include<math.h>
#include<algorithm> using namespace std; int main(){
double seven,five,three,two;
int a,humber[5842]={0},n=0;
for(seven=1;seven<=2000000000;seven*=7){
for(five=1;seven*five<=2000000000;five*=5){
for(three=1;seven*five*three<=2000000000;three*=3){
for(two=1;seven*five*three*two<=2000000000;two*=2){
humber[n]=seven*five*three*two;
n++;
}
}
}
}
sort(humber,humber+5842);
while((cin>>a)&&a!=0){
if(a%10==1&&a%100!=11){ //!!! cout format
cout<<"The "<<a<<"st humble number is "<<humber[a-1]<<"."<<endl;
continue;
}
if(a%10==2&&a%100!=12){
cout<<"The "<<a<<"nd humble number is "<<humber[a-1]<<"."<<endl;
continue;
}
if(a%10==3&&a%100!=13){
cout<<"The "<<a<<"rd humble number is "<<humber[a-1]<<"."<<endl;
continue;
}
cout<<"The "<<a<<"th humble number is "<<humber[a-1]<<"."<<endl; }
return 0;
}

ZOJ 1095 Humble Numbers的更多相关文章

  1. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  2. HDU - The number of divisors(约数) about Humble Numbers

    Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence ...

  3. A - Humble Numbers

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Pract ...

  4. The number of divisors(约数) about Humble Numbers[HDU1492]

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  5. Humble Numbers

    Humble Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9988 Accepted: 4665 Descri ...

  6. 洛谷P2723 丑数 Humble Numbers

    P2723 丑数 Humble Numbers 52通过 138提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目背景 对于一给定的素数 ...

  7. HDU 1058 Humble Numbers (DP)

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  8. HDOJ 1058 Humble Numbers(打表过)

    Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...

  9. The number of divisors(约数) about Humble Numbers

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

随机推荐

  1. 完美实现自己的GetProcAddress函数(转载)

    我们知道kernel32.dll里有一个GetProcAddress函数,可以找到模块中的函数地址,函数原型是这样的: WINBASEAPI FARPROC WINAPI GetProcAddress ...

  2. 关于http断点续传相关的RANGE这个header

    <?php //1.txt内容"1234567890" socketData('127.0.0.1','/1.txt',80,"RANGE:bytes=0-0\r\ ...

  3. Sticks(poj1011/uva307)

    题目大意: 乔治有一些碎木棒,是通过将一些相等长度的原始木棒折断得到的,给出碎木棒的总数和各自的长度,求最小的可能的原始木棒的长度:(就是将一些正整数分组,每组加起来和相等,使和尽可能小) 一开始做p ...

  4. NOIP2005 等价表达式 解题报告

    明明进了中学之后,学到了代数表达式.有一天,他碰到一个很麻烦的选择题.这个题目的题干中首先给出了一个代数表达式,然后列出了若干选项,每个选项也是一个代数表达式,题目的要求是判断选项中哪些代数表达式是和 ...

  5. WCF如何通过契约加编码方式调用

    WCF采用基于契约的服务调用方法,通过System.ServiceModel.ChannelFactory<TChannel>直接创建服务代理对象. 创建服务代理 public stati ...

  6. inoic是什么

    本篇只侧重框架提供的功能和能力的研究,请关注后续实际部署使用体验. 一.inoic是什么? inoic是一个可以使用Web技术以hybird方式开发移动app的前端开源框架. 二.inoic框架特点 ...

  7. node开发 npm install -g express-generator@4

    Node forever : 1,forever start --uid test start app.js 2,forever start --uid test start -a app.js 3, ...

  8. async = require('async')

    var mongoose = require('mongoose'), async = require('async'); mongoose.connect('localhost', 'learn-m ...

  9. FCKEditor文件上传提示信息的汉化

    FCKEditor文件上传提示信息的汉化在FCKeditor中,虽然可以自动监测客户端语言,但是仍有小部分信息未能得到汉化.例如上传图片.Flash时,上传成功和上传失败的对话框提示信息均为英文,只要 ...

  10. JAVA每日一记

    1.两个最基本的java回收算法:复制算法和标记清理算法                 复制算法:两个区域A和B,初始对象在A,继续存活的对象被转移到B.此为新生代最常用的算法            ...