HDU 1058 Humble Numbers (打表)

题目链接:HDU 1058 Humble Numbers

题意:一些数他们的素数因子只有2,3,5,7。求这些数。

因为这些数的因子只可能是2,3,5,7。所以通过2,3,5,7这个四个数构造这个数列,这个数列靠后的数必定是前面的数乘上2,3,5,7得到。



AC代码:


#include<stdio.h>
#include<set>
#define ll __int64
using namespace std;
set<ll> s;
set<ll>::iterator it;
ll a[5]={2,3,5,7};
ll ans[7000];
void find()
{
	ll i;
	s.clear();
	s.insert(1);
	for(i=0;i<4;i++)
		s.insert(a[i]);
	for(i=0;i<4;i++)
	{
		for(it=s.begin();it!=s.end();it++)
		{
			ll temp=(*it)*a[i];
			if(temp>2000000000)
				break;
			s.insert(temp);
		}
	}
	ll count=1;
	for(it=s.begin();it!=s.end();it++)
		ans[count++]=*it;
}
int main()
{
	find();
	ll n;
	while(scanf("%I64d",&n)!=EOF,n)
	{
		if(n%100>10 && n%100<20)
			printf("The %I64dth humble number is ",n);
		else if(n%10==1)
			printf("The %I64dst humble number is ",n);
		else if(n%10==2)
			printf("The %I64dnd humble number is ",n);
		else if(n%10==3)
			printf("The %I64drd humble number is ",n);
		else
			printf("The %I64dth humble number is ",n);
		printf("%I64d.\n",ans[n]);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值