http://acm.hdu.edu.cn/showproblem.php?pid=1058
对于这个问题呢 我一直纠结了很久 毕竟我刚刚学算法哦 很多东西都不会 我刚开始的思路是这样的 一个一个来找 素因素是 2,3,5,7 的都可以 后面发现 这样有问题太大了要从一一直到2000000000 做错了。。 最后百度看一下别人怎么做的
其实™是从 因素开始来做的
你发现这张图片有什么 区别吗
2:得出递推方程:
下面 我们来看具体ac代码哦 注意输出就行了
#include<iostream>
using namespace std;
int a[5900]={0,1};
int main()
{
int n,sum,min;
int p[5]={0,1,1,1,1},m[5]={0,2,3,5,7};
for(int i=2;i<5843;i++)
{
min=2000000010;
for(int j=1;j<=4;j++)
{
if(m[j]*a[p[j]]<min)
min=m[j]*a[p[j]];
}
a[i]=min;
for(int j=1;j<=4;j++)
{
if(m[j]*a[p[j]]==min)
{
p[j]++;
}
}
}
while(cin>>n,n)
{
if (n%100/10!=1)
{
switch(n%10)
{
case 1:
{
cout<<"The "<<n<<"st humble number is "<<a[n]<<"."<<endl;
break;
}
case 2:
{
cout<<"The "<<n<<"nd humble number is "<<a[n]<<"."<<endl;
break;
}
case 3:
{
cout<<"The "<<n<<"rd humble number is "<<a[n]<<"."<<endl;
break;
}
default :
{
cout<<"The "<<n<<"th humble number is "<<a[n]<<"."<<endl;
}
}
}
else cout<<"The "<<n<<"th humble number is "<<a[n]<<"."<<endl;
}
return 0;
}