标签:
http://poj.org/problem?id=1338
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 22968 | Accepted: 10218 |
Description
Input
Output
Sample Input
1
2
9
0
Sample Output
1
2
10
Source
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include<queue> #include<stack> #include<algorithm> using namespace std; const int maxn=1502; const int INF=0x3f3f3f3f; int ugly[maxn]= {0, 1}; void Init() { int num2=2, num3=3, num5=5; int i, j, k, t; i=j=k=1; for(int x=2; x<maxn; x++) { t=min(num2, min(num3, num5)); ugly[x]=t; if(t==num2) num2=ugly[++i]*2; if(t==num3) num3=ugly[++j]*3; if(t==num5) num5=ugly[++k]*5; } } int main() { Init(); int n; while(scanf("%d", &n), n) printf("%d\n", ugly[n]); return 0; }
标签:
原文地址:http://www.cnblogs.com/w-y-1/p/5752065.html