丑数

如果一个数的所有质因子全部由2, 3, 5, 7中的任意多个组成, 那我们把这个数称为H数. 比如: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27 是前 20 个H数 

指出第n个H数是多少. 
Input多组输入. 每组输入包含一个正整数 n (1 <= n <= 5842). 

n = 0 时结束输入. 
Output对于每组输入, 输出 "The nth humble number is number.". 
注意 "nth"的词尾应根据整数 n 的序数词词尾而改变. 
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.

每个数都由2,3,5,7组成,所以新的数由之前的数生成。

/*
	打表 ,速度更快
*/ 
#include<stdio.h>
#include<algorithm> 
using namespace std;
int main()
{
	int n1=1;
	long long a[6000]={0};
	int m1,m2,m3,m4;
	m1=m2=m3=m4=1;
	a[1]=1;
	n1++;
	while(n1<=5842)
	{
		int min1=min(a[m1]*2,a[m2]*3);
		int min2=min(a[m3]*5,a[m4]*7);
		a[n1]=min(min1,min2);
		if(a[n1]==a[m1]*2)m1++;
		if(a[n1]==a[m2]*3)m2++;
		if(a[n1]==a[m3]*5)m3++;
		if(a[n1]==a[m4]*7)m4++;
		n1++;
		
	}
	int n;
	while(scanf("%d",&n)==1)
	{	if(n==0)break;
		int tem=n%10;
		int t=n+1;
		if(tem==1&&n%100!=11)
			printf("The %dst humble number is %lld.\n",n,a[t-1]);
		if(tem==2&&n%100!=12)
			printf("The %dnd humble number is %lld.\n",n,a[t-1]);
		if(tem==3&&n%100!=13)
			printf("The %drd humble number is %lld.\n",n,a[t-1]);
		if(tem!=1&&tem!=2&&tem!=3||n%100>10&&n%100<14)
			printf("The %dth humble number is %lld.\n",n,a[t-1]);
	}
		
		
	
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值