C. Beautiful Set
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The first line contains integer k (10 ≤ k ≤ 5000) that shows how many numbers the required beautiful set should have.

Output

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.

Examples
input
10
output
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的更多相关文章

  1. 使用Beautiful Soup编写一个爬虫 系列随笔汇总

    这几篇博文只是为了记录学习Beautiful Soup的过程,不仅方便自己以后查看,也许能帮到同样在学习这个技术的朋友.通过学习Beautiful Soup基础知识 完成了一个简单的爬虫服务:从all ...

  2. 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(1): 基础知识Beautiful Soup

    开始学习网络数据挖掘方面的知识,首先从Beautiful Soup入手(Beautiful Soup是一个Python库,功能是从HTML和XML中解析数据),打算以三篇博文纪录学习Beautiful ...

  3. Python爬虫学习(11):Beautiful Soup的使用

    之前我们从网页中提取重要信息主要是通过自己编写正则表达式完成的,但是如果你觉得正则表达式很好写的话,那你估计不是地球人了,而且很容易出问题.下边要介绍的Beautiful Soup就可以帮你简化这些操 ...

  4. 推荐一些python Beautiful Soup学习网址

    前言:这几天忙着写分析报告,实在没精力去研究django,虽然抽时间去看了几遍中文文档,还是等实际实践后写几篇操作文章吧! 正文:以下是本人前段时间学习bs4库找的一些网址,在学习的可以参考下,有点多 ...

  5. 数位DP CF 55D Beautiful numbers

    题目链接 题意:定义"beautiful number"为一个数n能整除所有数位上非0的数字 分析:即n是数位所有数字的最小公倍数的倍数.LCM(1到9)=2520.n满足是252 ...

  6. 错误 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 ...

  7. hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)

    hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...

  8. Python学习笔记之Beautiful Soup

    如何在Python3.x中使用Beautiful Soup 1.BeautifulSoup中文文档:http://www.crummy.com/software/BeautifulSoup/bs3/d ...

  9. Python Beautiful Soup学习之HTML标签补全功能

    Beautiful Soup是一个非常流行的Python模块.该模块可以解析网页,并提供定位内容的便捷接口. 使用下面两个命令安装: pip install beautifulsoup4 或者 sud ...

随机推荐

  1. python第三天 列表和元组

    枚举 for in enumerate 循环输出字符串的内容并且输出它的索引信息: #判断索引为5的字符串是不是"您" is in Python提供了⼤量的内置数据结构,包含了列表 ...

  2. 【模板】无源汇有上下界可行流(网络流)/ZOJ2314

    先导知识 网络最大流 题目链接 https://vjudge.net/problem/ZOJ-2314 题目大意 多组数据,第一行为数据组数 \(T\). 对于每一组数据,第一行为 \(n,m\) 表 ...

  3. C#gridview颜色提示

    OnRowCreated="gridStatistic_RowCreated private void FillUI() { gridStatistic.DataSource = dtSta ...

  4. jsp的动态包含和静态包含

    jsp的动态包含和静态包含 例如:提取一个公共的页面(top.jsp)到/WEB-INF/jsp/common/目录下 动态包含: 被包含的页面也会独立编译,生成字节码文件,一般包含页面信息频繁变化的 ...

  5. C++ 类型转换(C风格的强制转换):

    转https://www.cnblogs.com/Allen-rg/p/6999360.html C++ 类型转换(C风格的强制转换): 在C++基本的数据类型中,可以分为四类:整型,浮点型,字符型, ...

  6. 帮助IT业告别内卷,哪项变革最能被寄予厚望?

    近日,中国软件行业协会发布<2021年中国低代码/无代码市场研究报告>,其中提到:我国低代码整体市场规模已达数十亿规模,并将在未来五年保持49.5%的复合增长率.低代码成为整个中国ICT产 ...

  7. Web容器(tomcat服务器)处理JSP文件请求的三个阶段

    Web容器(tomcat服务器)处理JSP文件请求的三个阶段 翻译:编写好的jsp文件被web容器中的jsp引擎转换成java源码. 编译:翻译成java源码的jsp文件会被编译成可被计算机执行的字节 ...

  8. OAuth2.0实战:认证、资源服务异常自定义!

    大家好,我是不才陈某~ 这是<Spring Security 进阶>的第4篇文章,往期文章如下: 实战!Spring Boot Security+JWT前后端分离架构登录认证! 妹子始终没 ...

  9. 开发中的PR和MR

    GitLab的是Pull Request缩写.GitHub则是Merge Request也就是MR. 当项目下载后进行更改并提交,每次过程算一次PR,一般会加入管理员审核,通过才能合并到master主 ...

  10. TypeScript 数据类型---枚举 (Enum)

    一.基础用法 1.默认值 从0开始递增+1 enum Color {Red, Green, Blue} let c: Color = Color.Red; let d: Color = Color.G ...