poj 2247 Humble Numbers

/* Name:poj 2247 Humble Numbers Author:Unimen Date: 24/04/11 16:51 */ /* 解题报告: 1、递推计算,并打表,注意计算质因数的方法 2、注意输出格式 */ #include <iostream> using namespace std; int anResult[6000]; int MinTwo(int a, int b) { return a<b ? a : b; } int MinFour(int a, int b, int c, int d) { int nTemp = MinTwo(a, b); nTemp = MinTwo(nTemp, c); nTemp = MinTwo(nTemp, d); return nTemp; } int main() { int p2, p3, p5, p7; p2 = p3 = p5 = p7 = 1; int n = 1; anResult [1] = 1; while(n <= 5842) { anResult[++n] = MinFour(2*anResult[p2], 3*anResult[p3], 5*anResult[p5], 7*anResult[p7]); if(2*anResult[p2] == anResult[n]) ++p2; if(3*anResult[p3] == anResult[n]) ++p3; if(5*anResult[p5] == anResult[n]) ++p5; if(7*anResult[p7] == anResult[n]) ++p7; } while(cin>>n && n) { int ten = n / 10 % 10; int nTemp = n; nTemp = n % 10; cout<<"The "<<n; if(1==nTemp && ten!=1) cout<<"st"; else if(2==nTemp && ten!=1) cout<<"nd"; else if(3==nTemp && ten!=1) cout<<"rd"; else cout<<"th"; cout<<" humble number is "<<anResult[n]<<"."<<endl; } return 0; }

你可能感兴趣的:(c,Date,Numbers)