当前位置: 代码迷 >> 综合 >> HDU 1058 Humble Numbers -
  详细解决方案

HDU 1058 Humble Numbers -

热度:82   发布时间:2023-09-23 06:37:44.0

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1058

打表

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define min4(a,b,c,d) min(min(a,b),min(c,d))
int a[5842+5];
char* s[]={"th","st","nd","rd"};
int Get(int n){if(n%100>=10&&n%100<=20) return 0;else return n%10<=3&&n%10>=1?n%10:0;
}
void init()
{int p2,p3,p5,p7,p;p=p2=p3=p5=p7=1; a[1]=1;while(p<=5842) {a[++p]=min4(2*a[p2],3*a[p3],5*a[p5],7*a[p7]);if(2*a[p2]==a[p]) p2++;if(3*a[p3]==a[p]) p3++;if(5*a[p5]==a[p]) p5++;if(7*a[p7]==a[p]) p7++;}
}
int main()
{int n;init();while(cin>>n,n)printf("The %d%s humble number is %d.\n",n,s[Get(n)],a[n]);return 0;
}