首页 技术 正文
技术 2022年11月10日
0 收藏 556 点赞 4,271 浏览 1080 个字

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<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#define ll long long
#define INF 1500000000000000000
using namespace std; struct cmp{bool operator()(ll a,ll b){return a>b;}};
priority_queue<ll,vector<ll>,cmp> q;
map<ll,int> m;ll a[1000005],M,p;void init_(){
q.push(1);
while(q.top()<INF){
ll x=q.top();q.pop();
a[p++]=x;
if(!m.count(2*x)) {q.push(2*x);m[2*x]=1;}
if(!m.count(3*x)) {q.push(3*x);m[3*x]=1;}
if(!m.count(5*x)) {q.push(5*x);m[5*x]=1;}
} //cout<<p<<endl;
scanf("%d",&M);
}void work(){
while(M--){
ll x;
scanf("%lld",&x); printf("%lld\n",*lower_bound(a+1,a+p+1,x));
}
}int main(){
// freopen("01.in","r",stdin); init_();
work(); fclose(stdin);fclose(stdout);return 0;
}

  

做一个优先队列,用已经有的数生成更大的数

map去重,lower_bound二分加速

INF少打了一个0,不开心

51Nod 1010 只包含因子2 3 5的数 Label:None

时间还算可以吧,我觉得主要是询问的时间,因为 计数器菌 表示这样的数在数据范围内只有1w+

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,493
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297