51nod1010【二分】

打表+二分

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL inf=1e18+100;
LL a[20000];
int num;
void init()
{
    num=0;
    LL i,j,z;
    for(i=1;i<inf;i=i*2){
        for(j=1;j*i<inf;j=j*3){
            for(z=1;i*j*z<inf;z=z*5){
                a[num++]=i*j*z;
            }
        }
    }
    sort(a+1,a+num);
}
int main()
{
    init();
    int T;
    scanf("%d",&T);
    while(T--)
    {
        LL n;
        scanf("%lld",&n);
        int left=1,right=num-1;
        while(left<right)
        {
            int mid=left+(right-left)/2;
            if(a[mid]>=n)
                right=mid;
            else
                left=mid+1;
        }
        printf("%lld\n",a[left]);
    }
    return 0;
}
posted @ 2016-09-19 16:34  see_you_later  阅读(93)  评论(0编辑  收藏  举报