标签:
# include <iostream> # include <vector> using namespace std; long long int a[6000]; long long int Min(long long int a, long long int b, long long int c, long long int d) { if(a <= b && a <= c && a <= d) return a; if(b <= a && b <= c && b <= d) return b; if(c <= b && c <= a && c <= d) return c; if(d <= b && d <= c && d <= a) return d; } int main() { a[1] = 1; a[2] = 2; a[3] = 3; a[4] = 4; int n = 1; int num2, num3, num5, num7; num2 = num3 = num5 = num7 = 1; while(n < 5842) { n++; a[n] = Min(2 * a[num2], 3 * a[num3], 5 * a[num5], 7 * a[num7]); if(a[n] == 2 * a[num2]) num2++; if(a[n] == 3 * a[num3]) num3++; if(a[n] == 5 * a[num5]) num5++; if(a[n] == 7 * a[num7]) num7++; //cout << a[n] << endl; } while(cin >> n) { if(n == 0) break; if(n % 10 == 1 && n % 100 != 11) cout << "The "<< n << "st humble number is " << a[n] << "." << endl; else if(n % 10 == 2 && n % 100 != 12) cout << "The "<< n << "nd humble number is " << a[n] << "." << endl; else if(n % 10 == 3 && n % 100 != 13) cout << "The "<< n << "rd humble number is " << a[n] << "." << endl; else cout << "The "<< n << "th humble number is " << a[n] << "." << endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/lyf-acm/p/5448474.html