51nod 1010 stl/数论/二分
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行1个数N(1 <= N <= 10^18)
共T行,每行1个数,输出>= n的最小的只包含因子2 3 5的数。
5
1
8
13
35
77
2
8
15
36
80
这个就是筛丑数把,可以用stl里的容器操作,要筛10915个出来就好了一个也不能少不然会WA的,紫书例题。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<ctime>
#include<functional>
#include<algorithm>
using namespace std;
#define LL long long
LL num[] = { ,, };
priority_queue<LL, vector<LL>, greater<LL> >q;
set<LL>s;
int main()
{
q.push();
s.insert();
bool ok = ;
int sum = ;
while (sum<=) {
LL u = q.top();q.pop();
for (int i = ;i < ;++i) {
LL x = u*num[i];
if (x< || x>1e18) { continue; }
if (!s.count(x)) { sum++;s.insert(x);q.push(x); }
}
}
LL T, N;
s.erase();
cin >> T;
while (T--) {
scanf("%lld", &N);
printf("%lld\n", *s.lower_bound(N));
}
//system("pause");
return ;
}
51nod 1010 stl/数论/二分的更多相关文章
- STL之二分查找 (Binary search in STL)
STL之二分查找 (Binary search in STL) Section I正确区分不同的查找算法count,find,binary_search,lower_bound,upper_bound ...
- CJOJ 1308 【HNOI 2002 】营业额统计 / CodeVS 1296 营业额统计(STL,二分)
CJOJ 1308 [HNOI 2002 ]营业额统计 / CodeVS 1296 营业额统计(STL,二分) Description Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一 ...
- 51nod 1010 只包含因子2 3 5的数 二分答案
1010 只包含因子2 3 5的数 K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 > ...
- 51Nod 1010 只包含因子2 3 5的数 | 预处理+二分
Input示例 5 1 8 13 35 77 Output示例 2 8 15 36 80 分析:将所有的只含有2 3 5因子的数打一个表保存在一个数组里,然后二分查找第一个>=数组里的数,输出 ...
- 51Nod 1010 只包含因子2 3 5的数(打表+二分)
K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...
- 51nod 1010 只包含因子2 3 5的数 打表
只包含因子2 3 5的数 题目连接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 Description K的 ...
- 51nod 1010 只包含因子2 3 5的数 && poj - 1338 Ugly Numbers(打表)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 http://poj.org/problem?id=1338 首先 ...
- 【转】STL之二分查找 (Binary search in STL)
Section I正确区分不同的查找算法count,find,binary_search,lower_bound,upper_bound,equal_range 本文是对Effective STL第4 ...
- HDU 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
随机推荐
- ThreadLocal (二):什么时候使用 InheritableThreadLocal
一.ThreadLocal 在父子线程传递的问题 public class InheritableThreadLocalDemo { // 全局变量 // static ThreadLocal< ...
- mapper文件提示:No data sources are configured to run this sql
mapper文件发出黄色警告. 输入数据库用户名和密码等等. 自动同步ok 就会发现代码变绿了,ok
- CSRF(Cross Site Request Forgery, 跨站请求伪造)
一.CSRF 背景与介绍 CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网络的攻击方式,它在 2007 年曾被列为互联网 20 大安全隐患之一.其他安全隐患, ...
- 流量分析系统--zookeeper集群部署
安装zookeeper mkdir apps tar -zxvf zookeeper-3.4.5.tar.gz -C apps [root@mini1 zookeeper-3.4.5]# rm -rf ...
- 小程序学习第二天 认识框架WXML
一.初级小程序HelloWorld 心得: (1)progect.config.json :app的个性化设置 (2)一个小程序至少包括两个文件 (2.1)app.json 小程序全局配置 ...
- 服务中的 API 网关(API Gateway)
我们知道在微服务架构风格中,一个大应用被拆分成为了多个小的服务系统提供出来,这些小的系统他们可以自成体系,也就是说这些小系统可以拥有自己的数据库,框架甚至语言等,这些小系统通常以提供 Rest Api ...
- springboot-vue项目前台1
- 超酷Loading进度条
在线演示 本地下载
- php的正则表达式
这篇文章介绍的内容是关于php的正则表达式 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下. 正则表达式是一种描述字符串结果的语法规则,是一个特定的格式化模式,可以匹配.替换.截取匹配 ...
- UI基础_transform
#import "ViewController.h" typedef enum { ButtonTypeLeft = 1, ButtonTypeRight, ButtonTypeU ...