First, I want to screen out the prime number table, and then 1 ~ 2000000000 enumeration tables.
Then I thought of the unique decomposition theorem, but how can I implement it .. We still need to work hard ..
The Discuss code, code ~
~~~~
DP idea. If DP [I] is humble numbers, then DP [I] * 2, DP [I] * 3, DP [I] * 5, DP [I] * 7 will all be humble numbers.
Therefore, you only need to pay attention to continuity.
# Include <cstdio> # include <algorithm> # include <cmath> # define ll _ int64 # define n 6000 using namespace STD; ll f [N] = {0, 1 }; void dp () {int X, Y, p, q; X = y = P = q = 1; for (INT I = 2; I <= 5842; I ++) {// take the minimum value to maintain continuity f [I] = min (F [x] * 2, min (F [y] * 3, min (F [p] * 5, f [Q] * 7); If (F [I] = f [x] * 2) x ++; // take the next one as the factor if (F [I] = f [y] * 3) y ++; If (F [I] = f [p] * 5) P ++; If (F [I] = f [Q] * 7) q ++ ;}} int main () {dp (); int N; while (~ Scanf ("% d", & N), n) {// The output notes 11,12, 13,113. If (N % 10 = 1 & amp; n % 100! = 11) printf ("the % DST humble number is % i64d. \ n ", N, F [N]); else if (N % 10 = 2 & N % 100! = 12) printf ("the % DND humble number is % i64d. \ n ", N, F [N]); else if (N % 10 = 3 & N % 100! = 13) printf ("the % DRD humble number is % i64d. \ n ", N, F [N]); else printf (" the % DTH humble number is % i64d. \ n ", N, F [N]);} return 0 ;}
~~~~
See a pretty brute-force code. See the following ~
#include<stdio.h>#include<math.h>#include<algorithm>using namespace std;const int maxn = 2000000000;int main(){ __int64 i, j, k, r, g = 1, a[6000]; for(i=0; i<31 && pow(2,i)<=maxn; i++) for(j=0; j<20 && pow(2,i)*pow(3,j)<=maxn; j++) for(k=0; k<14 && pow(2,i)*pow(3,j)*pow(5,k)<=maxn; k++) for(r=0; r<12 && pow(2,i)*pow(3,j)*pow(5,k)*pow(7,r)<=maxn; r++) a[g++] = pow(2,i)*pow(3,j)*pow(5,k)*pow(7,r); sort(a+1,a+g+1); int t; while(~scanf("%d", &t), t) { printf("The %d", t); if(t%10 == 1 && t%100 != 11) printf("st "); else if(t%10 == 2 && t%100 != 12) printf("nd "); else if(t%10 == 3 && t%100 != 13) printf("rd "); else printf("th "); printf("humble number is %d.\n", a[t]); } return 0;}