Humble Number

Problem 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.

题目大意:求出以2,3,5,7为因子的第n个数字。

代码如下:注意111后面跟th

 # include<iostream>
# include<cstdio>
# include<cstring>
# include<cstdlib>
# define LL __int64 using namespace std; int cmp(const void *a,const void *b)
{
return *(int *)a - *(int *)b;
}
LL dp[],num;
void init()
{
num = ;
LL i,j,k,m;
for(i=; i<=; i*=)
{
for(j=; i*j<=; j*=)
{
for(k=; i*j*k<=; k*=)
{
for(m=; i*j*k*m<=; m*=)
{
dp[num] = i*j*k*m;
//printf("dp[%I64d] = %I64d\n",num,dp[num]);num定义成了__int64位,之前一直输出%d,看结果一直不对,坑
num++;
}
}
}
}
qsort(dp,num,sizeof(dp[]),cmp);
}
int main()
{
init();
int n,i,j,a,b,c;
while(scanf("%d",&n)&&n)
{
if(n%== &&n% != )
printf("The %dst humble number is ",n);
else if(n%== &&n% != )
printf("The %dnd humble number is ",n);
else if(n%== &&n% != )
printf("The %drd humble number is ",n);
else
printf("The %dth humble number is ",n);
printf("%I64d.\n",dp[n-]);
}
return ;
}

HDU 1058 Humble Number的更多相关文章

  1. HDOJ(HDU).1058 Humble Numbers (DP)

    HDOJ(HDU).1058 Humble Numbers (DP) 点我挑战题目 题意分析 水 代码总览 /* Title:HDOJ.1058 Author:pengwill Date:2017-2 ...

  2. HDU 1058 Humble Numbers(离线打表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1058 解题报告:输入一个n,输出第n个质因子只有2,3,5,7的数. 用了离线打表,因为n最大只有58 ...

  3. hdu 1058 Humble Numbers

    这题应该是用dp来做的吧,但一时不想思考了,写了个很暴力的,类似模拟打表,然后排序即可,要注意的是输出的格式,在这里wa了一发,看了别人的代码才知道哪些情况没考虑到. #include<cstd ...

  4. HDU 1058 Humble Numbers【DP】

    题意:给出丑数的定义,只含有2,3,5,7这四个素数因子的数称为素数.求第n个丑数. 可以先观察几个丑数得出规律 1:dp[1] 2:min(1*2,1*3,1*5,1*7) 3:min(2*2,1* ...

  5. HDU 1058 Humble Numbers (DP)

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

  6. hdu 1058:Humble Numbers(动态规划 DP)

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

  7. HDU 1058 Humble Numbers (动规+寻找丑数问题)

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

  8. hdu 1058 Humble Numbers(构造?枚举?)

    题意: 一个数的质因子如果只是2,3,5,7中的若干个.则这个数叫做humble number. 例如:1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 1 ...

  9. hdu 1058 dp.Humble Numbers

    Humble Numbers Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Subm ...

随机推荐

  1. 数据文件个数大于1024时ORACLE数据文件FILE_ID及RELATIVE_FNO的变化示例

    通过ROWID计算数据块的相关信息:  --详见: 数据文件头块保留大小.ROWID.数据文件最大大小等数据库限制的说明 根据small file tablespace的ROWID,计算出表空间.数据 ...

  2. MFC版美女找茬

    今天心情:捡了个闲暇. 前几天工作出了个漏洞,电话会议时候怎么都是忽大忽小的声音,实在没听清电话会议的内容,完了依据想象交了一个设计方案,之后便是赋闲. 进入正题,美女找茬实现不难,没有设计上的难度, ...

  3. 解读BOM与COM

    概念: 1.BOM(Browser Object Model): 浏览器对象模型,从名字上就能知道它和浏览器关系密切. 浏览器的非常多行为是通过JavaScript控制的.比如打开新窗体.打开关闭标签 ...

  4. [置顶] 最小生成树Prim算法

    二话不说直接贴代码 原图传送门:http://www.tyut.edu.cn/kecheng1/site01/suanfayanshi/minispantree.asp 但是上面展现的是克鲁斯卡尔算法 ...

  5. iOS开发:AVPlayer实现流音频边播边存

    1. AVPlayer简介 AVPlayer存在于AVFoundation中,可以播放视频和音频,可以理解为一个随身听 AVPlayer的关联类: AVAsset:一个抽象类,不能直接使用,代表一个要 ...

  6. 在centos上使用yum安装redis及php扩展php-redis

    .wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -ivh epel-rele ...

  7. 如何打开“USB调试”模式?

    请首先确认您的系统版本, 点击「设置」-「关于手机」查看您当前的手机版本号. 如果您使用的是 Android 3.2及以下系统,请按以下步骤操作: STEP1:在应用列表选择「设置」进入系统设置菜单: ...

  8. Ambiguous mapping found. Cannot map 'xxxxController' bean method

    1.背景 今天要做一个demo,从github上clone一个springmvc mybatis的工程(https://github.com/komamitsu/Spring-MVC-sample-u ...

  9. Java基础知识强化之IO流笔记63:随机访问流RandomAccessFile

    1. 随机访问流RandomAccessFile RandomAccessFile类不属于流,是Object类的子类.但它融合了InputStream和OutputStream的功能.支持对随机访问文 ...

  10. CSS3 动态魔方的展示

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...