codeforce364(div1.C). Beautiful Set
1 second
256 megabytes
standard input
standard output
We'll call a set of positive integers a beautiful if the following condition fulfills: for any prime p, if
, then
. In other words, if one number from the set is divisible by prime p, then at least half of numbers from the set is divisible by p.
Your task is to find any beautiful set, where the number of elements is equal to k and each element doesn't exceed 2k2.
The first line contains integer k (10 ≤ k ≤ 5000) that shows how many numbers the required beautiful set should have.
In the first line print k space-separated integers that are a beautiful set. If there are multiple such sets, you are allowed to print any of them.
10
16 18 24 27 36 48 54 72 108 144
思路:贪心+dfs;
因为每个出现的素数都要在集合中至少有(n+1)/2个与他不互质的数,你可以发现所有的素数都小于17,那么也就是那些数最多就会由6个素数构成,那么我们每次贪心优先选每个素数都是那个数的因子的数就行,还有选数不能超过某个范围,所以我们先以某个数结尾,从小到大dfs找到那个至少有n个数的那个结束的素数,然后以他结尾再dfs一遍取前n个数就是答案。
1 #include<stdio.h>
2 #include<algorithm>
3 #include<stdlib.h>
4 #include<iostream>
5 #include<string.h>
6 #include<queue>
7 #include<math.h>
8 typedef long long LL;
9 using namespace std;
10 LL prime[7]= {2,3,5,7,11,13};
11 LL ans[10000];
12 LL ak=0;
13 LL N;
14 LL v;
15 int flag[7];
16 int maxx_fl[7];
17 void dfs(LL top,LL d,LL ap,bool fla)
18 { if( ap > 2*v*v)return ;
19 else if(d == -1&&fla)
20 {
21 int i,j;
22 ans[ak++]=ap;
23 return ;
24 }
25 else if(d == -1)
26 {
27 ak++;
28 return ;
29 }
30
31 else
32 {
33 LL cf=top;
34 LL as=ap;
35 while(cf > prime[d])
36 {
37 cf /= prime[d];
38 as *= prime[d];
39 flag[d]++;
40 dfs(cf,d-1,as,fla);
41 }
42 dfs(top,d-1,ap,fla);
43 }
44 }
45 int main(void)
46 {
47 LL n;
48 while(scanf("%I64d",&n)!=EOF)
49 {
50 memset(flag,0,sizeof(flag));
51 LL i,j;
52 ak=0;
53 v=n;
54 for(i=0; i<=5; i++)
55 {
56 ak=0;dfs(2*n*n,i,1,false);
57 if(ak>=v)
58 {break;}
59 }
60 ak=0;
61 dfs(2*n*n,i,1,true);
62 printf("%I64d",ans[0]);
63 for(i=1; i<n; i++)
64 printf(" %I64d",ans[i]);
65 printf("\n");
66 }
67 return 0;
68 }
codeforce364(div1.C). Beautiful Set的更多相关文章
- 使用Beautiful Soup编写一个爬虫 系列随笔汇总
这几篇博文只是为了记录学习Beautiful Soup的过程,不仅方便自己以后查看,也许能帮到同样在学习这个技术的朋友.通过学习Beautiful Soup基础知识 完成了一个简单的爬虫服务:从all ...
- 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(1): 基础知识Beautiful Soup
开始学习网络数据挖掘方面的知识,首先从Beautiful Soup入手(Beautiful Soup是一个Python库,功能是从HTML和XML中解析数据),打算以三篇博文纪录学习Beautiful ...
- Python爬虫学习(11):Beautiful Soup的使用
之前我们从网页中提取重要信息主要是通过自己编写正则表达式完成的,但是如果你觉得正则表达式很好写的话,那你估计不是地球人了,而且很容易出问题.下边要介绍的Beautiful Soup就可以帮你简化这些操 ...
- 推荐一些python Beautiful Soup学习网址
前言:这几天忙着写分析报告,实在没精力去研究django,虽然抽时间去看了几遍中文文档,还是等实际实践后写几篇操作文章吧! 正文:以下是本人前段时间学习bs4库找的一些网址,在学习的可以参考下,有点多 ...
- 数位DP CF 55D Beautiful numbers
题目链接 题意:定义"beautiful number"为一个数n能整除所有数位上非0的数字 分析:即n是数位所有数字的最小公倍数的倍数.LCM(1到9)=2520.n满足是252 ...
- 错误 You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work
Win 10 下python3.6 使用Beautiful Soup 4错误 You are trying to run the Python 2 version of Beautiful ...
- hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)
hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...
- Python学习笔记之Beautiful Soup
如何在Python3.x中使用Beautiful Soup 1.BeautifulSoup中文文档:http://www.crummy.com/software/BeautifulSoup/bs3/d ...
- Python Beautiful Soup学习之HTML标签补全功能
Beautiful Soup是一个非常流行的Python模块.该模块可以解析网页,并提供定位内容的便捷接口. 使用下面两个命令安装: pip install beautifulsoup4 或者 sud ...
随机推荐
- 巩固javaweb第十六天
巩固内容: 下拉框 在注册功能中,地区的选择使用了下拉框,可以从地区选项中选择一个地区.在这个 例子中,只允许选择一个,而在有些情况下,下拉框可以进行多选.所以,从功能上来说, 下拉框具有单选按钮和复 ...
- A Child's History of England.6
It was a British Prince named Vortigern who took this resolution, and who made a treaty of friendshi ...
- 【STM8】SPI通讯
这篇内容有点长,如果有人想透过我的博客学习STM8的SPI,那是我的荣幸 首先我要先说大纲,这样大家心里比较有底,可以把精力都用在SPI理解上 [SPI初步介绍]:介绍SPI如何接线.名称解释.通讯注 ...
- 记录一下使用MySQL的left join时,遇到的坑
# 现象 left join在我们使用mysql查询的过程中可谓非常常见,比如博客里一篇文章有多少条评论.商城里一个货物有多少评论.一条评论有多少个赞等等.但是由于对join.on.where等关键字 ...
- eclipse.ini顺序
-vmargs需放在-Dfile.encoding=UTF-8之前,否则会出现乱码 举例: -startup plugins/org.eclipse.equinox.launcher_1.3.0.v2 ...
- JSP常见的状态码
1.404错误 -- 找不到访问的页面或资源 a.URL输入错误: b.未部署项目. 2.500错误 -- JSP页面代码有错误 3.302状态码+200状态码 -- 重定向 4.200状态码 -- ...
- 使用JSP实现输出
一.在JSP页面添加java代码,实现输出,java代码写在<% %>中. 代码示例1: <body> <!-- HTML注释 --> <%-- JSP注释 ...
- OAuth2.0实战:认证、资源服务异常自定义!
大家好,我是不才陈某~ 这是<Spring Security 进阶>的第4篇文章,往期文章如下: 实战!Spring Boot Security+JWT前后端分离架构登录认证! 妹子始终没 ...
- Mysql安全加固
1.确保MYSQL_PWD环境变量未设置 描述 MYSQL_PWD环境变量的使用意味着MYSQL凭证的明文存储,极大增加MySQL凭据泄露风险. 加固建议 删除系统环境变量中MySQL密码(MYSQL ...
- heap exploit about ptmalloc in glibc version 2.31
学习的一下高版本的libc的利用方式. 项目地址:https://github.com/StarCross-Tech/heap_exploit_2.31 tcache_dup 源代码: 1 #incl ...