POJ 2247 Humble Numbers G++
程序员文章站
2022-03-23 17:31:55
...
只由因子2,3,5,7组成的数称为humble数,所有humble数按升序排列。求第n个humble数。
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
//#include <iomanip>
using namespace std;
//谢谢博友文章
vector<long long> hs;
int main()
{
//cout<<pow(2,31)<<endl;
//cout<<pow(3,20)<<endl;
//cout<<pow(5,14)<<endl;
//cout<<pow(7,12)<<endl;
//cout<< setprecision(5)<<scientific<<2000000000<<endl;
for(int a=0;a<32;a++)
{
for(int b=0;b<21;b++)
{
for(int c=0;c<15;c++)
{
for(int d=0;d<13;d++)
{
long long t=pow(2,a)*pow(3,b)*pow(5,c)*pow(7,d);
if((t<2000000001)&&(t>0))
{
hs.push_back(t);
}
}
}
}
}
sort(hs.begin(),hs.end());
while(1)
{
int th;
cin>>th;
if(th==0)
{
break;
}
//谢谢博友 十位数字为1的都为th,其余情况下看各位数字,各位数字1, 2, 3分别对应st, nd, rd,其余也为th
if((th%10==1)&&(th%100!=11))
{
cout<<"The "<<th<<"st humble number is "<<hs[th-1]<<"."<<endl;
}else if((th%10==2)&&(th%100!=12))
{
cout<<"The "<<th<<"nd humble number is "<<hs[th-1]<<"."<<endl;
}else if((th%10==3)&&(th%100!=13))
{
cout<<"The "<<th<<"rd humble number is "<<hs[th-1]<<"."<<endl;
}else
{
cout<<"The "<<th<<"th humble number is "<<hs[th-1]<<"."<<endl;
}
}
return 0;
}
上一篇: POJ 1316 Self Numbers G++
下一篇: Python全栈介绍MySQL 数据库