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 ...
随机推荐
- [NOIP2018TG]赛道修建
[NOIP2018TG]赛道修建 考场上multiset调不出啊啊啊!!! 首先肯定是二分答案 做树形dp,f[i]表示i点的子树两两匹配后剩下的最长长度 匹配可以用multiset维护 但是菊花图跑 ...
- Python——用正则求时间差
如有求时间差的需求,可直接套用此方法: import time true_time=time.mktime(time.strptime('2017-09-11 08:30:00','%Y-%m-%d ...
- samba了解
1. samba是一个网络服务器,用于Linux和Windows之间共享文件 2,amba服务的启动.停止.重启 service smb start|stop|restart3. 掌握samba ...
- 解决后台无法进入提示DedeCMS Error: (PHP 5.3 and above) Please set 'request_order' ini value
最近小美眉的网站被盯上了,被添加了非常多的dubo页面,删除了5w多个文件,但还是不停的增加,因为网站权重还可以,很多都被收录了,结果可想而知,ytkah帮她迁移,在迁移网站时遇到了一些问题,后台登录 ...
- Hexo+yilia博客首页不显示全文,显示more,截断文章。
个人主页:https://www.yuehan.online hexo new “xxx” 在md文档中 插入<!--more-->即可. 现在博客:www.wangyurui.top
- JDBC注册驱动程序的三种方式
1. Class.forName("com.mysql.jdbc.Driver");//加载数据库驱动 Class.forName("com.mysql.jdbc.Dri ...
- 常用MS-SQL写法整理
这里整理日常会用到的一些写法,一些常规的group by,系统函数等用法不在这里做记录了,大家有什么好的写法也可以分享下 1 sql操作xml内容(sp_xml_preparedocument和ope ...
- django路由系统之反向生成url
from niubin.service import v1 from django.urls import reverse from django.shortcuts import HttpRespo ...
- STL之map、set灵活使用
1.LA 5908/UVA1517 Tracking RFIDs 题意:给出s个传感器的位置,以及其感应范围.如果某个方向上有墙,则该方向上感应距离减1.现在有w个墙,给出p个物品的位置,问其能被几个 ...
- DP专题(不定期更新)
1.UVa 11584 Partitioning by Palindromes(字符串区间dp) 题意:给出一个字符串,划分为若干字串,保证每个字串都是回文串,同时划分数目最小. 思路:dp[i]表示 ...