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. OpenGL小试牛刀第一季

    效果截图:代码展示:using System;using System.Collections.Generic;using System.ComponentModel;using System.Dat ...

  2. UVALive 5031 Graph and Queries (Treap)

    删除边的操作不容易实现,那么就先离线然后逆序来做. 逆序就变成了合并,用并存集判断连通,用Treap树来维护一个连通分量里的名次. Treap = Tree + Heap.用一个随机的优先级来平衡搜索 ...

  3. session添加登录次数限制

    session 中设置了生存期,20分钟,输入密码错误次数保存到session 中,过一段时间自动解除: //登陆的用户名或者密码出错次数 int n = 0; if(logintimes == nu ...

  4. NOIP模拟赛 麻将

    [题目描述] 众所周知,麻将是我们国家的国粹.这段时间,小D也迷上了麻将这个老少皆宜的游戏. 小D觉得这些不同规则的麻将太麻烦了,所以他集合了很多种麻将规则创造出了一套D麻将.下面是D麻将的几个特点: ...

  5. 201621123080 《Java程序设计》第13周学习总结

    201621123080 <Java程序设计>第13周学习总结 1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 为你的系统增加网络功能( ...

  6. 12Vim在系统配置中的应用示例

    Vim 在系统配置中的应用示例 1. 配置主机名称 为了便于咱局域网中查找某台特定的主机,后者对主机进行区分,除了要有IP地址外,还要为主机配置一个主机名,主机名之间可以通过这个类似于域名的名称来相互 ...

  7. mysql按指定顺序排序

    select id,name from htms_center_freight_users where id in(114,112,91,223,134) order by find_in_set(i ...

  8. python导出开发环境

    1.导出开发环境的依赖包 本地开发完后,再把代码给别人之前,需要 pip freeze > pip123.txt 2.其他环境安装依赖包 pip install -r pip123.txt 其他 ...

  9. 解决 viewer.js 动态更新图片导致无法预览的问题

    1.viewer.js 使用 Demo http://fengyuanchen.github.io/viewerjs/ 2.viewer.js 下载地址 https://github.com/feng ...

  10. GoF23种设计模式之行为型模式之观察者模式

    一.概述        定义对象之间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新.二.适用性1.当一个抽象模型有两个方面,其中一个方面依赖于另一方面的时 ...