51Nod 1010 只包含因子2 3 5的数 | 预处理+二分

Input示例
5
1
8
13
35
77
Output示例
2
8
15
36
80

分析:
将所有的只含有2 3 5因子的数打一个表保存在一个数组里,然后二分查找第一个>=数组里的数,输出
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,a,n) for(int i = a; i < n; i++)
#define repe(i,a,n) for(int i = a; i <= n; i++)
#define per(i,n,a) for(int i = n; i >= a; i--)
#define clc(a,b) memset(a,b,sizeof(a))
#define INF 1e18+100
#define N 1000010
typedef long long LL;
const int MAXN = 70*70*70;
LL a[MAXN];
int cnt = 0;
void Init()
{
    cnt = 0;
    for(LL i=1; i<INF; i*=2)///(注意i,j,k是LL的)
        for(LL j=1; j*i<INF; j*=3)
            for(LL k=1; i*j*k<INF; k*=5)
                    a[cnt++] = i*j*k;
}
int main()
{
    Init();
    sort(a, a+cnt);
    int T;
    cin>>T;
    while(T--)
    {
        LL n;
        scanf("%lld",&n);
        printf("%lld
",a[lower_bound(a+1,a+cnt+1,n)-a]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/kimsimple/p/7463803.html