首页 > 其他分享 >UVa 443 / POJ 2247 Humble Numbers (4因子-丑数&STL灵活运用)

UVa 443 / POJ 2247 Humble Numbers (4因子-丑数&STL灵活运用)

时间:2023-04-12 11:34:14浏览次数:63  
标签:丑数 humble 10 443 Humble number str insert include


443 - Humble Numbers

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=384

http://poj.org/problem?id=2247

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 Specification

The input consists of one or more test cases. Each test case consists of one integer n with 

 . Input is terminated by a value of zero (0) for n.

Output Specification

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


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



用set秒杀。


类似的题:

POJ 1338 Ugly Numbers

POJ 2545 Hamming Problem


完整代码:

/*0.018s*/

#include<cstdio>
#include<cstring>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;

set<ll> s;
set<ll>::iterator it;
char str[5];

int main()
{
	s.insert(1);
	it = s.begin();
	///要满足第5842个数为2000000000,s.size()要达到这么多
	///同时为了不爆上限,类型设为long long
	while (s.size() < 7000)
	{
		s.insert(*it * 2);
		s.insert(*it * 3);
		s.insert(*it * 5);
		s.insert(*it * 7);
		++it;
	}
	vector<ll> v(s.begin(), s.end());
	int n;
	while (scanf("%d", &n), n)
	{
		if (n % 10 == 1 && (n % 100) / 10 != 1)
			strcpy(str, "st");
		else if (n % 10 == 2 && (n % 100) / 10 != 1)
			strcpy(str, "nd");
		else if (n % 10 == 3 && (n % 100) / 10 != 1)
			strcpy(str, "rd");
		else
			strcpy(str, "th");
		printf("The %d%s humble number is %lld.\n", n, str, v[n - 1]);
	}
	return 0;
}



标签:丑数,humble,10,443,Humble,number,str,insert,include
From: https://blog.51cto.com/u_5535544/6185341

相关文章

  • git 出现 连接超时443的情况
    解决Failedtoconnecttogithub.comport443:connectiontimedout  1)取消代理gitconfig--global --unsethttp.proxygitconfig--global--unsethttps.proxy(2)获得成功!   ......
  • Kubernetes——问题与解决方案一、k8s重启报错 :The connection to the server 192.168
    摘要Kubernetes运行过程中出现的各种问题,因此本人整理出本人遇到的有关于的k8s的相关问题和解决方案一、k8s重启报错:Theconnectiontotheserver192.168.102.149:6443wasrefused1.1现象k8s重启报错#kubectlgetpodsTheconnectiontotheserverxxx:6443wasrefused......
  • git提交443
    通过IDEALPUSH时提示以下错误fatal:unabletoaccess'https://github.com/18618450592/mygit.git/':OpenSSLSSL_connect:SSL_ERROR_SYSCALLinconnectiontogithub.com:44315:21:59.671:[..\..\mygit]git-ccredential.helper=-ccore.quotepath=false-cl......
  • 解决方案:The connection to the server ip:6443 was refused - did you specify the r
    一、概述1、k8s有时候会报错Theconnectiontotheserverip:6443wasrefused-didyouspecifytherighthostorport,本文档提供几种可能产生该报错的原因和排障思......
  • [kubernetes]Calico运行异常:dial tcp 10.96.0.1:443: connect: connection refused
    [kubernetes]Calico运行异常:dialtcp10.96.0.1:443:connect:connectionrefuseddingpwen于2022-04-2710:33:12发布5309收藏分类专栏:云原生web开发文章标签:ku......
  • P4434 [COCI2017-2018#2] ​​Usmjeri
    知识点:lca,种类并查集新生赛原题。什么嘛,我还是长了一点手的嘛简述给定一棵\(n\)个节点的树,初始时每条边方向不确定,同时给定\(m\)组约束,第\(i\)组约束为\((a_i,......
  • 【数组】LeetCode 264. 丑数 II
    题目链接264.丑数II思路根据题目中的样例,可以进行拆分\[1,1×2,1×3,2×2,1×5,2×3,2×4,3×3,3×4,3×5\]观察能发现,这些多项式能分成下面三组:\[乘2:......
  • Modbus网关ZLAN5443D 在锂电池干燥箱的应用
    在锂离子电池生产过程中,将正负极片辊压绕卷再放入电池盒之后,须对锂电池电芯极组进行烘烤干燥。相信大家也了解水分对锂电池的性能影响是很大的,需要注液前在装配车间将锂离......
  • ssh on 443
    SomeExamplesHostgithub.comHostnamessh.github.comPort443UsergitHostgitlab.comHostnamealtssh.gitlab.comPort443UsergitHostbit......
  • HDOJ1058Humble Numbers(丑数)
    HumbleNumbersTimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):27739    AcceptedSubmission(s):......