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 ...
随机推荐
- Google服务器架构图解简析
无疑是互联网时代最闪亮的明星.截止到今天为止,Google美国主站在Alexa排名已经连续3年第一,Alexa Top100中,各国的Google分站竟然霸占了超过20多个名额,不得不令人感叹Goog ...
- 如何优雅地将printf的打印保存在文件中?
我们都知道,一般使用printf的打印都会直接打印在终端,如果想要保存在文件里呢?我想你可能想到的是重定向.例如: $ program > result.txt 这样printf的输出就存储在r ...
- C语言之内核中的struct list_head 结构体
以下地址文章解释很好 http://blog.chinaunix.net/uid-27122224-id-3277511.html 对下面的结构体分析 1 struct person 2 { 3 in ...
- JVM1 JVM与Java体系结构
目录 JVM与Java体系结构 虚拟机与Java虚拟机 虚拟机 Java虚拟机 JVM的位置 JVM的整体结构 Java代码执行流程 JVM的架构模型 基于栈的指令级架构 基于寄存器的指令级架构 两种 ...
- 23. 关于Ubuntu中Could not get lock /var/lib/dpkg/lock解决方案
原文:https://blog.csdn.net/u011596455/article/details/60322568 版权声明:本文为博主原创文章,转载请附上博文链接! 在Ubuntu中,有时候运 ...
- Undefined symbols for architecture arm64:问题
Undefined symbols for architecture arm64: "_sqlite3_prepare_v2", referenced from: +[HMJSch ...
- Linux 性能优化笔记:应用监控
指标监控 跟系统监控一样,在构建应用程序的监控系统之前,首先也需要确定,到底需要监控哪些指标.特别是要清楚,有哪些指标可以用来快速确认应用程序的性能问题. 对系统资源的监控,USE 法简单有效,却不代 ...
- MH/T4029.3 IFPL报文解析
MH/T4029.3是民航业用来规定飞行计划相关数据交互的规范,今天我们先来解析下其中I类的IFPL报文. 我们先来看看IFPL报文长啥样. ZCZC -TITLE IFPL -FILTIM 0109 ...
- Java 数据类型:集合接口Collection之Set接口HashSet类;LinkedHashSet;TreeSet 类
Collection 之 Set 实现类: HashSet TreeSet 特点: 无序. 元素不可重复. (如果试图添加一个已经有的元素到一个Set集合中,那么会添失败,add()方法返回false ...
- JAVA验证手机号码是否正确
PhoneUtils.java package com.common.util; import java.util.regex.Matcher; import java.util.regex.Patt ...