ZOJ 1095 Humble Numbers
题目大意:定义了一种数字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的更多相关文章
- [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 ...
- 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 ...
- A - Humble Numbers
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
- The number of divisors(约数) about Humble Numbers[HDU1492]
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- Humble Numbers
Humble Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9988 Accepted: 4665 Descri ...
- 洛谷P2723 丑数 Humble Numbers
P2723 丑数 Humble Numbers 52通过 138提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交 讨论 题解 最新讨论 暂时没有讨论 题目背景 对于一给定的素数 ...
- HDU 1058 Humble Numbers (DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDOJ 1058 Humble Numbers(打表过)
Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...
- The number of divisors(约数) about Humble Numbers
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
随机推荐
- POJ 1077 && HDU 1043 Eight A*算法,bfs,康托展开,hash 难度:3
http://poj.org/problem?id=1077 http://acm.hdu.edu.cn/showproblem.php?pid=1043 X=a[n]*(n-1)!+a[n-1]*( ...
- 2014北邮新生归来赛解题报告d-e
D: 399. Who Is Joyful 时间限制 3000 ms 内存限制 65536 KB 题目描述 There are several little buddies standing in a ...
- mongo .update
db.classes.update({"count":{$gt:20}},{$set:{"name":"c4"}},false,false) ...
- 初步比较zeromq vs. wcf
用最简单的Calculator比较zeromq的req-rep模式 vs. wcf的http和net.tcp模式,看哪一种的传输性能更高. 1.比较结果如下 方式 耗费时间 wcf_http_sing ...
- websocket++编译过程
websocket++ 是一个开源 websocket 库,使用websocket++ 能够开发基于websocket 服务. 前一段时间成功编译 websocket++ ,分享一下,编译websoc ...
- sql 给数据库表 字段 添加注释
最近发现一些代码生成器 有针对注释做一个很好的转化,之前建表的时候 没有这块的注释.现在想增加,专门去看了下 如何增加注释 1 -- 表加注释 2 EXEC sys.sp_addextendedpro ...
- RPI学习--环境搭建_无线网络的连接
这里不讨论无线网卡的驱动问题,假设内核已经支持了该网卡. 发现命令行下添加无线网络比较麻烦,于是利用图形桌面的工具(WiFi Config)先配置好,在回到字符终端,发现网络已经配置好了 查看内网ip ...
- hadoop 8步走
1.1读取hdfs中的文件.每一行解析成一个<k,v>.每一个键值对调用一次map函数 解析成2个<k,v>,分别是<0, hello you>< ...
- (转)js函数参数设置默认值
原文:http://www.cnblogs.com/RightDear/archive/2013/06/26/3156652.html js函数参数设置默认值 php有个很方便的用法是在定义函数时 ...
- 多比Web 3D展示(3D机房/3D监控)中间件多比Web 3D展示(3D机房/3D监控)中间件免费下载购买地址
多比3D是实现3D场景搭建的软件开发包,可以创建广泛的3D应用,适用于高端制造.能源.国防军工.教育科研.城市规划及建筑环艺.生物医学等领域的虚拟仿真,应用于虚拟展示.虚拟设计.方案评审.虚拟装配.虚 ...