题目链接:http://poj.org/problem?id=1338

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
#define N 12345

int main( )
{
    int a[1505]= {0};
    int b=0,c=0,d=0,i,t;
    a[0]=1;
    for(i=1; i<1500; i++)
    {
        if(2*a[b]>3*a[c])
            t=a[c]*3;
        else
            t=a[b]*2;
        if(t>a[d]*5)
            t=a[d]*5;

        if(t == 2*a[b]) b++;
        if(t == 3*a[c]) c++;
        if(t == 5*a[d]) d++;

        a[i]=t;
    }
    int n;
    while(scanf("%d", &n),n)
    {
        printf("%d\n", a[n-1]);
    }
    return 0;
}

 

题目链接:http://poj.org/problem?id=1338

posted on 2016-07-16 15:21  惟愿。。。  阅读(113)  评论(0编辑  收藏  举报