您的位置:首页 > 其它

51Nod 1010 只包含因子2 3 5的数(打表+二分)

2017-03-28 18:39 260 查看
1010 只包含因子2 3 5的数


基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题


 收藏


 关注

K的因子中只包含2 3 5。满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15。
所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数。
例如:n = 13,S中 >= 13的最小的数是15,所以输出15。

Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行1个数N(1 <= N <= 10^18)


Output
共T行,每行1个数,输出>= n的最小的只包含因子2 3 5的数。


Input示例
5
1
8
13
35
77


Output示例
2
8
15
36
80

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define MAX 1e18+100
__int64 a[110000];
__int64 l=0;
void solve()
{
__int64 i, j, k;

for(i=1; i<MAX; i=i*2)
{
for(j=1; j*i<MAX; j=j*3)
{
for(k=1; k*j*i<MAX; k=k*5)
{
a[l++]=i*j*k;
}
}
}
}
int main()
{
solve();
sort(a,a+l);//注意要排序
__int64 t, n, ans;
scanf("%I64d", &t);
while(t--)
{
scanf("%I64d",&n);
ans=*lower_bound(a+1,a+l,n);
printf("%I64d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: