您的位置:首页 > 其它

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

2017-09-01 16:24 274 查看

 

 

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\n",a[lower_bound(a+1,a+cnt+1,n)-a]);
}
return 0;
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: