Humble Numbers

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

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.
 
 
代码:
#include<iostream>
#include<set>
using namespace std;
typedef long long LL;
LL er=1,san=1,wu=1,qi=1;
LL minn(const LL &a,const LL &b,const LL &c,const LL &d)
{
LL t=a;
if(b<t)
t=b;
if(c<t)
t=c;
if(d<t)
t=d;
//下面都要用if而非else-if 出现重复的数时才可以多个数均被++
if(t==a)
er++;
if(t==b)
san++;
if(t==c)
wu++;
if(t==d)
qi++;
return t;
}
int main(void)
{
LL i;
LL list[5900]={1,1};
for (i=2; i<5900; i++)
{
list[i]=minn(2*list[er],3*list[san],5*list[wu],7*list[qi]);
}
int n;
while (cin>>n&&n)
{
if(n%10==1&&n%100!=11)
printf("The %dst humble number is %lld.\n",n,list[n]);
else if(n%10==2&&n%100!=12)
printf("The %dnd humble number is %lld.\n",n,list[n]);
else if(n%10==3&&n%100!=13)
printf("The %drd humble number is %lld.\n",n,list[n]);
else
printf("The %dth humble number is %lld.\n",n,list[n]);
}
return 0;
}

HDU——1058Humble Numbers(找规律)的更多相关文章

  1. HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...

  2. hdu 5047 大数找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...

  3. SGU 169 Numbers (找规律)

    题意:中文题,直接忽略... 析:先说说我的思路,我一看这个题第一感觉就是要找规律,要是挨着算,猴年马月都跑不完,更何况时间限制是0.25s,怎么找规律呢,我算了一下前10位,分别是8,1,1,3,1 ...

  4. SGU-169 Numbers(找规律)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=169 解题报告: P(n)定义为n的所有位数的乘积,例如P(1243)=1*2*3* ...

  5. hdu 5106 组合数学+找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5106 给定n和r,要求算出[0,r)之间所有n-onebit数的和,n-onebit数是所有数位中1的个数. 对 ...

  6. URAL 2070 Interesting Numbers (找规律)

    题意:在[L, R]之间求:x是个素数,因子个数是素数,同时满足两个条件,或者同时不满足两个条件的数的个数. 析:很明显所有的素数,因数都是2,是素数,所以我们只要算不是素数但因子是素数的数目就好,然 ...

  7. Doom HDU - 5239 (找规律+线段树)

     题目链接: D - Doom  HDU - 5239  题目大意:首先是T组测试样例,然后n个数,m次询问,然后每一次询问给你一个区间,问你这个这段区间的加上上一次的和是多少,查询完之后,这段区间里 ...

  8. hdu 4708(暴力+找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 思路:由于N不大,并且我们可以发现通过旋转得到的4个对角线的点的位置关系,以及所要旋转的最小步数 ...

  9. hdu 4759 大数+找规律 ***

    题目意思很简单. 就是洗牌,抽出奇数和偶数,要么奇数放前面,要么偶数放前面. 总共2^N张牌. 需要问的是,给了A X B Y  问经过若干洗牌后,第A个位置是X,第B个位置是Y 是不是可能的. Ja ...

随机推荐

  1. 5分钟部署一个Hello World Servlet到CloudFoundry

    首先从我的Github下载我写好的hello world Servlet到本地. 安装Maven,然后执行命令行mvn clean install,确保build成功,在项目根目录的target文件夹 ...

  2. UVA 1451 Average平均值 (数形结合,斜率优化)

    摘要:数形结合,斜率优化,单调队列. 题意:求一个长度为n的01串的子串,子串长度至少为L,平均值应该尽量大,多个满足条件取长度最短,还有多个的话,取起点最靠左. 求出前缀和S[i],令点Pi表示(i ...

  3. mac安装webpack失败

    最近开始接触构建工具webpack,公司电脑是 windows,而我自己的呢是mac.本来以为在自己电脑安装很简单,但是出了点问题,所以写出来分享下. 这里用npm的方式安装,首先你要安装node.j ...

  4. 爬虫3_python2

    # coding=utf-8 import urllib params=urllib.urlencode({'t':1,'eggs':2,'bacon':0})#现在大多数网站都是动态网页,需要你动态 ...

  5. css实现页面文字不换行、自动换行、强制换行

    强制不换行 div{ white-space:nowrap; } 自动换行 div{ word-wrap: break-word; word-break: normal; } 强制英文单词断行 div ...

  6. presenting view controller

    Present ViewController详解 Present ViewController Modally 一.主要用途 弹出模态ViewController是IOS变成中很有用的一个技术,UIK ...

  7. c++基本配置属性页

    怎么调试一个项目. 需要配置好环境. 在一个release版本的环境中,调试要用release-debug版本,一般不用debug版本. 配置类型一般不变.

  8. (73)zabbix用户认证方式 内建、HTTP Basic、LDAP

    公司大大小小众多系统,不同系统不同的账号密码,管理上相当复杂,后来慢慢出现了SSO等账号统一验证,其他zabbix也提供了类似的方法,或许有些公司便可以使用公司提供的账号来登录zabbix了. zab ...

  9. 使用powershell批量更新git仓库

    Get-ChildItem D:\GitHub\NetCore | ForEach-Object -Process{ cd $_.name; git pull; cd ../ }

  10. pre-commit钩子,代码质量检查

    目前基本使用三款js代码质量检查工具: jslint, jshint, eslint.许多IDE里面也有对应的检查插件,在每次ctrl + s 保存文件的时候,检查当前文件是否符合规范,保证代码质量. ...