您的位置:首页 > 其它

POJ 2247 Humble Numbers

2015-08-05 14:42 459 查看
#include<iostream>
#include<algorithm>
#define maxnum 2000000000
using namespace std;
int a[5850]={0};

int main(){
long long n2=1,n3=1,n5=1,n7=1;
int n,count=0;
while(n2<=maxnum){
n3=1;
while(n2*n3<=maxnum){
n5=1;
while(n2*n3*n5<=maxnum){
n7=1;
while(n2*n3*n5*n7<=maxnum){
a[++count]=n2*n3*n5*n7;
n7*=7;
}
n5*=5;
}
n3*=3;
}
n2*=2;
}
sort(&a[1], &a[count+1] );
while(cin>>n,n){
if(n%10==1 && n%100!=11)
cout<<"The "<<n<<"st humble number is "<<a
<<"."<<endl;
else if(n%10==2 && n%100!=12)
cout<<"The "<<n<<"nd humble number is "<<a
<<"."<<endl;
else if(n%10==3 && n%100!=13)
cout<<"The "<<n<<"rd humble number is "<<a
<<"."<<endl;
else
cout<<"The "<<n<<"th humble number is "<<a
<<"."<<endl;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: