一、题目编号:
1004
二、简单题意:
1004
二、简单题意:
因子只有2,3,5,7的数称为humble number,输出第n个humble number。
三、解题思路形成过程
初始化算出所有的humble number存起来,输出即可。
初始化算出所有的humble number存起来,输出即可。
四、感想
题目不难,但是细节很重要。要注意最后的输出格式!!
题目不难,但是细节很重要。要注意最后的输出格式!!
五、AC代码
#include<iostream>
#include<cstring>
using namespace std;
long long humble[5843];
int main()
{
humble[1]=1;
int k1=1,k2=1,k3=1,k4=1,n;
for(int i=2;i<=5842;i++)
{
humble[i]=min(min(humble[k1]*2,humble[k2]*3),min(humble[k3]*5,humble[k4]*7));
if(humble[i]==humble[k1]*2)
k1++;
if(humble[i]==humble[k2]*3)
k2++;
if(humble[i]==humble[k3]*5)
k3++;
if(humble[i]==humble[k4]*7)
k4++;
}
while(cin>>n&&n!=0)
{
long long result=humble[n];
string s;
if(n%100!=11&&n%10==1)
{
s="st";
}
else if(n%100!=12&&n%10==2)
{
s="nd";
}
else if(n%100!=13&&n%10==3)
{
s="rd";
}
else
{
s="th";
}
cout<<"The"<<" "<<n<<s<<" "<<"humble number is"<<" "<<result<<"."<<endl;
}
return 0;
}
#include<cstring>
using namespace std;
long long humble[5843];
int main()
{
humble[1]=1;
int k1=1,k2=1,k3=1,k4=1,n;
for(int i=2;i<=5842;i++)
{
humble[i]=min(min(humble[k1]*2,humble[k2]*3),min(humble[k3]*5,humble[k4]*7));
if(humble[i]==humble[k1]*2)
k1++;
if(humble[i]==humble[k2]*3)
k2++;
if(humble[i]==humble[k3]*5)
k3++;
if(humble[i]==humble[k4]*7)
k4++;
}
while(cin>>n&&n!=0)
{
long long result=humble[n];
string s;
if(n%100!=11&&n%10==1)
{
s="st";
}
else if(n%100!=12&&n%10==2)
{
s="nd";
}
else if(n%100!=13&&n%10==3)
{
s="rd";
}
else
{
s="th";
}
cout<<"The"<<" "<<n<<s<<" "<<"humble number is"<<" "<<result<<"."<<endl;
}
return 0;
}