Write a program to find and print the nth element in this sequence
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long n[5842];
int main()
{
long long i,j,k,l,m,t,c=0;
for(i=1;c<=5842&&i<=2000000000;i=i*2)
for(j=1;c<=5842&&i*j<=2000000000;j=j*3)
for(k=1;c<=5842&&i*j*k<=2000000000;k=k*5)
for(l=1;c<=5842&&i*j*k*l<=2000000000;l=l*7)
{
t=i*j*k*l;
n[c++]=t;
}
sort(n,n+5842);
while(~scanf("%lld",&m)&&m!=0)
{
if(m%10==1&&m%100!=11)
printf("The %lldst humble number is %lld.\n",m,n[m-1]);
else if(m%10==2&&m%100!=12)
printf("The %lldnd humble number is %lld.\n",m,n[m-1]);
else if(m%10==3&&m%100!=13)
printf("The %lldrd humble number is %lld.\n",m,n[m-1]);
else
printf("The %lldth humble number is %lld.\n",m,n[m-1]);
}
return 0;
}
361



被折叠的 条评论
为什么被折叠?



