Problem D

Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)

Total Submission(s) : 7 Accepted Submission(s) : 3

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<queue>
#include<set>
#include<cstdio>
using namespace std;
set<long long int>a;
vector<long long int>c;
void js()
{
a.insert(1);
a.insert(2);
a.insert(3);
a.insert(4);
a.insert(5);
a.insert(6);
a.insert(7);
set<long long int>::iterator poi;
for(poi=a.begin();;poi++)
{
a.insert(2**poi);
a.insert(3**poi);
a.insert(5**poi);
a.insert(7**poi);
if(a.size()>6800)break;
}
for(poi=a.begin();poi!=a.end();poi++)
{
c.push_back(*poi);
}
}
string fuhao(int a)
{
if(a%100==11) return "th";
else if(a%100==12) return "th";
else if(a%100==13) return "th";
else if(a%10==1) return "st";
else if(a%10==2) return "nd";
else if(a%10==3) return "rd";
else return "th";
}
int main()
{
js();
int N;
while(scanf("%d",&N)&&N)
cout<<"The "<<N<<fuhao(N)<<" humble number is "<<c[N-1]<<'.'<<endl;
}

最新文章

  1. http——tinyhttp分析
  2. 学习Excel 十大函数
  3. javascript中日期格式与时间戳之间的转化
  4. 手机APP测试的几大点
  5. AEAI DP开发平台精要
  6. MAC中设置java环境变量和MAVEN
  7. [慢查优化]联表查询注意谁是驱动表 &amp; 你搞不清楚谁join谁更好时请放手让mysql自行判定
  8. linux-impdp的使用
  9. 安卓开发笔记——关于照片墙的实现(完美缓存策略LruCache+DiskLruCache)
  10. (转)在PHP语言中使用JSON
  11. 请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串&quot;+100&quot;,&quot;5e2&quot;,&quot;-123&quot;,&quot;3.1416&quot;和&quot;-1E-16&quot;都表示数值。 但是&quot;12e&quot;,&quot;1a3.14&quot;,&quot;1.2.3&quot;,&quot;+-5&quot;和&quot;12e+4.3&quot;都不是。
  12. Calendar中add函数和roll函数的用法及区别
  13. 添加redo日志组和添加日志组多元化
  14. Codeforces 903D Almost Difference
  15. 前言:JNI调用-简单使用
  16. 微信企业付款获取RSA
  17. element-ui 点击获取table的行索引
  18. 使用命令行登陆数据库配置文件修改 解决ora12528
  19. python 全栈开发,Day69(Django的视图层,Django的模板层)
  20. 程序中try、throw、catch三者之间的关系

热门文章

  1. qq群排名靠前最新方法
  2. ECSHOP数据表结构完整仔细说明教程 (http://www.ecshop119.com/ecshopjc-868.html)
  3. Vue-cli2.0 第3节 解读Vue-cli模板
  4. JS 浏览器BOM--&gt;open() 方法
  5. floyd最小环&amp;&amp;模板
  6. Java虚拟机类装载的原理及实现(转)
  7. fiddler composer post请求
  8. vuepress+gitee 构建在线项目文档
  9. 一站式WebAPI与认证授权服务
  10. 借助Python来实现的定量城市研究