Humble Numbers
Humble Numbers
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 9988 Accepted: 4665
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.
Write a program to find and print the nth element in this sequence.
Input
The input consists of one or more test cases. Each test case consists of one integer n with 1 <= n <= 5842. Input is terminated by a value of zero (0) for n.
Output
For each test case, print one line saying “The nth humble number is number.”. Depending on the value of n, the correct suffix “st”, “nd”, “rd”, or “th” for the ordinal number nth has to be used like it is shown in the sample output.
Sample Input
1
2
3
4
11
12
13
21
22
23
100
1000
5842
0
Sample Output
The 1st humble number is 1.
The 2nd humble number is 2.
The 3rd humble number is 3.
The 4th humble number is 4.
The 11th humble number is 12.
The 12th humble number is 14.
The 13th humble number is 15.
The 21st humble number is 28.
The 22nd humble number is 30.
The 23rd humble number is 32.
The 100th humble number is 450.
The 1000th humble number is 385875.
The 5842nd humble number is 2000000000.
Source
Ulm Local 1996
好恶心的输出格式
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#define LL long long
using namespace std;
const int INF = 0x3f3f3f3f;
const LL MAX = 2000000000;
LL A[10000];
int top;
int main()
{
//freopen("output.txt","w",stdout);
LL a,b,c,d;
top=0;
for(int i=0; i<=33; i++)
{
if(i==0)
{
a=1;
}
else
{
a*=2;
}
if(a>MAX)
{
break;
}
for(int j=0; j<=33; j++)
{
if(j==0)
{
b=1;
}
else
{
b*=3;
}
if(a*b>MAX)
{
break;
}
for(int k=0; k<=33; k++)
{
if(k==0)
{
c=1;
}
else
{
c*=5;
}
if(a*b*c>MAX)
{
break;
}
for(int s=0; s<=33; s++)
{
if(s==0)
{
d=1;
}
else
{
d*=7;
}
if(a*b*c*d>MAX)
{
break;
}
else
{
A[top++]=a*b*c*d;
}
}
}
}
}
sort(A,A+top);
int n;
while(scanf("%d",&n)&&n)
{
if(n%10==1&&(n%100>=20||n%100<10))
{
printf("The %dst humble number is %I64d.\n",n,A[n-1]);
}
else if(n%10==2&&(n%100>=20||n%100<10))
{
printf("The %dnd humble number is %I64d.\n",n,A[n-1]);
}
else if(n%10==3&&(n%100>=20||n%100<10))
{
printf("The %drd humble number is %I64d.\n",n,A[n-1]);
}
else
{
printf("The %dth humble number is %I64d.\n",n,A[n-1]);
}
}
return 0;
}
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 ...
- 洛谷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 ...
- HDU1058 Humble Numbers 【数论】
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
随机推荐
- javascript 函数参数之中的undefined(zz)
开始看到很多js函数里都带一个undefined的参数,很是疑惑,后来查了查,原来是这样.假如我们定义了一个函数function a(){ if(arg1===undefined) alert(&q ...
- PostgreSQL单机、同步复制、异步复制性能测试对比
测试环境: •测试机:PC •内存:8GB •CPU:Intel(R) Core(TM) i5-3450 3.10GHz •硬盘:HDD •数据量:20GB •测试工具:pgbench •Postgr ...
- hdu 2846 Repository
http://acm.hdu.edu.cn/showproblem.php?pid=2846 Repository Time Limit: 2000/1000 MS (Java/Others) ...
- [原创]java WEB学习笔记72:Struts2 学习之路-- 文件的上传下载,及上传下载相关问题
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- [转] FastJson---高性能JSON开发包
原文地址: FastJson---高性能JSON开发包 Fastjson介绍 Fastjson是一个Java语言编写的JSON处理器,由阿里巴巴公司开发.1.遵循http://json.org标准,为 ...
- 面向切面编程AOP:基于注解的配置
Aop编程就是面向编程的羝是切面,而切面是模块化横切关注点. -切面:横切关注点,被模块化的特殊对象. -通知:切面必须要完成的工作 -目标:被通知的对象 -代理:向目标对象应用通知之后创建的对象. ...
- HDU 1052 Tian Ji -- The Horse Racing(贪心)(2004 Asia Regional Shanghai)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Problem Description Here is a famous story in Ch ...
- mysql server安装及密码重置
官网上能下载到的mysql安装分两种:msi和zip安装 msi安装比较简单,直接下一步. 主要说zip格式的安装: 1.解压. zip解压后的文件夹改名后(也可以不改名)放在喜欢的位置.例如我放在C ...
- [php] 使用IDE的正则搜索代码
([^a-zA-Z_=$0-9/\[\>])('|"|,)?(\s*)store_banner(\s*)('|"|,)?([^a-zA-Z_=$0-9\/\(\]:]) 用在 ...
- 关于wxwidgets图形界面的关闭窗口的按钮无效的解决办法
这是使用wxsmith设计界面时的情况,如果用纯代码写的界面,关闭按钮就很奇怪地有效 道听途说,窗口的关闭是由一个方法控制着.大概是这样的: void PlainFrame::OnClose(wxCl ...