Codeforces Round #191 (Div. 2) B. Hungry Sequence(素数筛选法)
. Hungry Sequence
1 second
256 megabytes
standard input
standard output
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.
A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:
- Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
- For any two indices i and j (i < j), aj must not be divisible by ai.
Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.
The input contains a single integer: n (1 ≤ n ≤ 105).
Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one.
3
2 9 15
5
11 14 20 27 31 输出n个从小到大排列、每个数不超过范围的素数即可 AC Code:
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int maxn = ;
bool prime[maxn]; int main()
{
int n;
memset(prime, false, sizeof(prime));
for(int i = ; i * i < maxn; i++)
{
for(int j = ; i * j < maxn; j++)
prime[i*j] = true;
}
while(scanf("%d", &n) != EOF)
{
printf("");
for(int i = , j = ; i < n; j++)
{
if(prime[j] == false)
{
printf(" %d", j);
i++;
}
}
printf("\n");
}
return ;
}
Codeforces Round #191 (Div. 2) B. Hungry Sequence(素数筛选法)的更多相关文章
- 贪心 Codeforces Round #191 (Div. 2) A. Flipping Game
题目传送门 /* 贪心:暴力贪心水水 */ #include <cstdio> #include <algorithm> #include <cstring> us ...
- Codeforces Round #191 (Div. 2)
在div 188中,幸运的达成了这学期的一个目标:CF1800+,所以这次可以打星去做div2,有点爽. A.Flipping Game 直接枚举 B. Hungry Sequence 由于素数的分布 ...
- Codeforces Round #333 (Div. 1) B. Lipshitz Sequence 倍增 二分
B. Lipshitz Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/601/ ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its fi ...
- Codeforces Round #191 (Div. 2) D. Block Tower
D. Block Tower time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #191 (Div. 2)---A. Flipping Game
Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- codeforces水题100道 第二十题 Codeforces Round #191 (Div. 2) A. Flipping Game (brute force)
题目链接:http://www.codeforces.com/problemset/problem/327/A题意:你现在有n张牌,这些派一面是0,另一面是1.编号从1到n,你需要翻转[i,j]区间的 ...
随机推荐
- Transparent Flow Migration for NFV
Transparent Flow Migration for NFV 摘要 因为SDN提供的灵活性,NF之间存在着流量的迁入和迁出问题.而且NF也要根据相关的状态信息处理数据包,所以流量迁移必须满足以 ...
- Rsyslog的模板template详解
一. Template功能 根据用户需求指定任意格式 动态生成文件名 每个输出都使用了一些模板,包括针对文件的,针对用户消息等 备注: 旧版本:$template 新版本:template() V6之 ...
- url传带有汉字的参数乱码解决
url传带有汉字的参数乱码解决 var reg = new RegExp("(^|&)createName=([^&]*)(&|$)"); var r = ...
- 利用canvas对上传图片进行上传前压缩
利用谷歌调式工具发现,图片大小直接影响着首屏加载时间. 且考虑到后期服务端压力,图片压缩特别必要. 本文是前端利用canvas实现图片.参考文章:https://www.cnblogs.com/007 ...
- maven 添加tomcat依赖
https://my.oschina.net/angel243/blog/178554
- 因为NLS_LANG 造成 Oracle数据库丢失 中文字符集兼容问题的处理.
接着上一封blog. 因为sqlplus的 乱码问题 我修改了 注册表里面 NLS_LANG 的 value值.主要改动为: NLS_LANG source: SIMPLIFIED CHINESE_C ...
- Win2019 + Oracle18c SQLPLUS 命令行出现乱码的解决
1. Win2019 中文版 安装了 Oracle数据库, dbca 建库时选择的 的字符集是 ZHS16GBK 然后发现使用sqlplus 时有乱码的现象如图示: 2. csdn 上面有一个博客有解 ...
- PHP面向对象之接口
接口(interface)技术 什么是接口? 先看抽象类: abstract class 类名 { 属性1: 属性2: ..... 非抽象方法1: 非抽象方法2: ...... 抽象方法1: 抽 ...
- idea 复制数据库查询结果,粘贴直接生成insert into 语句
遇到一个场景,需要将数据库查询的结果导入到另外一个数据库中,给我的第一感受是,写程序,从数据库A中获取到数据,在插入到数据库B中. 但是Idea 可以直接复制查询结果,然后粘贴生成insert语句. ...
- 第193天:js---Math+Error+Number+Object总结
一.Math 随机选取 //随机选取 function getRandom (begin,end){ return Math.floor(Math.random()*(end-begin))+begi ...