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 1011 Sticks dfs,剪枝 难度:2
http://poj.org/problem?id=1011 要把所给的集合分成几个集合,每个集合相加之和ans相等,且ans最小,因为这个和ans只在[1,64*50]内,所以可以用dfs一试 首先 ...
- dancing link模板
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #i ...
- Mac OS X 卸载MySQL
sudo rm /usr/local/mysqlsudo rm -rf /usr/local/mysql*sudo rm -rf /Library/StartupItems/MySQLCOMsudo ...
- 【STL】-function object
// Generic findMax, with a function object, version #1 // Precondition, a.size() > 0 #include < ...
- Rhel6-lvs配置文档
系统环境: rhel6 x86_64 iptables and selinux disabled 相关网址:http://zh.linuxvirtualserver.org/ yum仓库配置: [rh ...
- 神州通,我看行---K2用户交流会华南站
主题:K2高级移动信息化解决方案DBToApp开发工具 嘉宾:神州通在线 张德阔 移动办公APP开发≠一般APP开发,你知道这几种企业管理移动APP开发模式吗? 原生APP开发模式Native 具有最 ...
- Allow windows service to "Interact with desktop"
Typically, services are designed to run unattended without any UI with any need to interact with des ...
- 如何搭建MVC + EF 框架
1.搭建MVC框架 1.1 VS2010:需要安装WPI 安装 ASP.NET MVC 4 和Visual Studio 2010 系统必备组件 如果上述链接无法打开,请访问:http://www.a ...
- android application plugins framework
android插件式开发 android application plugins framework http://code.google.com/p/android-application-plug ...
- copy和assign的使用和区别
1.使用copy和assign都可以进行修饰属性或者变量. 2.区别: (1)copy的使用:使用这个进行修饰的属性,当已经进行初始化之后,就无法再改变属性的数据. 如: @property (cop ...