Humble Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14343    Accepted Submission(s): 6229

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.
思路,对于任意一个数n,都可以由 n=∏q^r即由素数之积构成....
代码:

 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
/*策略打表实现存储*/
__int64 sav[];
int cmp(void const *a,void const *b)
{
return (*(__int64 *)a)-(*(__int64 *)b);
}
int work()
{
__int64 a,b,c,d,aa,bb,cc,dd;
int cnt=;
for(a=,aa=; ;a++)
{
if(a!=) aa*=;
if(aa>) break;
for(b=,bb=; ; b++)
{
if(b!=) bb*=;
if((aa*bb)>) break;
for(c=,cc=; ; c++)
{
if(c!=)cc*=;
if((aa*bb*cc)>) break;
for(d=,dd=; ;d++)
{
if(d!=) dd*=;
if((aa*bb*cc*dd)>) break;
sav[cnt++]=(aa*bb*cc*dd);
}
}
}
} return cnt;
}
int main()
{
int n;
qsort(sav,work(),sizeof(sav[]),cmp);
while(scanf("%d",&n),n)
{
int tem=n%;
printf("The ");
if(tem>&&tem<)
printf("%dth ",n);
else
{
tem%=;
if(tem==)
printf("%dst ",n);
else if(tem==)
printf("%dnd ",n);
else if(tem==)
printf("%drd ",n);
else
printf("%dth ",n);
}
printf("humble number is %I64d.\n",sav[n-]);
}
return ;
}

HDUOJ------1058 Humble Numbers的更多相关文章

  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 (DP)

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

  3. HDOJ 1058 Humble Numbers(打表过)

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

  4. Hdoj 1058.Humble Numbers 题解

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

  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 (动规+寻找丑数问题)

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

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

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

  8. hdu 1058 Humble Numbers

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

  9. 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* ...

  10. 【HDOJ】1058 Humble Numbers

    简单题,注意打表,以及输出格式.这里使用了可变参数. #include <stdio.h> #define MAXNUM 5845 #define ANS 2000000000 int b ...

随机推荐

  1. 0, \0, NULL

    字符串.字符数组输入.输出与'\0'的问题 原创首发,欢迎转载! 作者按 字符串.字符数组以"%s"格式输入时,以遇到'空格'为这个字符串输入结束. 字符串.字符数组以" ...

  2. 【BestCoder】【Round#44】

    模拟+Trie+桶排(归并?)+容斥 A 模(shou)拟(su)题= =感觉好像见过? 计算得分什么的…… //BestCoder #44 A #include<vector> #inc ...

  3. 3维DEMO: 抽奖圆盘

    抽奖圆盘 前些日子去超市,消费满一定钱数可以参加抽奖,就是在电视机上有个可旋转的圆盘,按一键开始,按一键抽奖结束.看到最大奖的扇形区域大约有个10度角的样子,按说中大奖的概率应该是36分之1.当然,这 ...

  4. Maximal Rectangle leetcode java

    题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones ...

  5. 刚開始学习的人非常有用:纯struts框架实现用户登陆

    本人新手一枚.也在学习ssh.高手建议从struts2開始学起,所以我就先仅仅用struts2写了一个demo.能够有助于理解struts2在项目中的作用. 首先简单了解一下struts2 的MVC模 ...

  6. Android -- ImageLoader本地缓存

    传送门 <Android -- ImageLoader简析>  http://www.cnblogs.com/yydcdut/p/4008097.html 本地缓存 在缓存文件时对文件名称 ...

  7. 模拟QQ心情图片上传预览

    出于安全性能的考虑,目前js端不支持获取本地图片进行预览,正好在做一款类似于QQ心情的发布框,找了不少jquery插件,没几个能满足需求,因此自己使用SWFuplad来实现这个图片上传预览. 先粘上以 ...

  8. 如何在MVC的ActionLink中应用Resource文件

    项目中建立Resources文件夹. 添加Resource文件,必须添加一个默认的,其他语言可以添加很多个.我这里只添加了一个中文的. 双击每个资源文件,将Access Modifier 设置成pub ...

  9. 【Node.js】初体验之安装和HelloWorld

    听说Node.js是个蛮吊的东东.中午休息时间有限,暂时看了下知道怎么安装和初步使用了. 1.安装: 到Node.js官网下载就可以了,才5M多点,双击后按步骤安装就可以了. 2."Hell ...

  10. ArcEngine10.x开发的许可问题

    1. ArcEngine9.x迁至ArcEngine10.x 相信很多同学都知道,在ArcEngine9.x下正常编译的代码到ArcEngine10.x会报错:ArcGIS version not s ...