解法

非常暴力的模拟。

一开始吧\(1 -> 2 \times 10^6\)全部扔进一个set里,如果之前取得数都是与原数组相同的,那么lower_bound一下找到set中大于等于它的数,否则直接取set中最小的数,然后枚举该数的所有质因数及其倍数,类似埃拉托斯特尼筛法删掉它们(如果它们在集合中的话)。

P.S. 不要用STL algorithm的lower_bound,极慢,用STL内部自带的lower_bound,快很多!

代码

#include <cstdio>
#include <set>
#include <algorithm>
#define ll long long using namespace std; inline int read(){
int x = 0; int zf = 1; char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
} int a[100005];
set<int> st; int main(){
int n = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
for (int i = 2; i <= 2e6; ++i)
st.insert(i);
bool flg = 0; int val; set<int>::iterator it;
for (int i = 1; i <= n; ++i){
(!flg) ? it = st.lower_bound(a[i]) : it = st.begin();
val = *it;
if (val > a[i]) flg = 1;
if (i != 1) printf(" ");
printf("%d", val);
st.erase(val);
for (int j = 2; j * j <= val; ++j){
if (!(val % j)){
for (int k = j; k <= 2e6; k += j)
st.erase(k);
}
while (!(val % j))
val /= j;
}
if (val > 1)
for (int k = val; k <= 2e6; k += val)
st.erase(k);
}
return 0;
}

[CF959D]Mahmoud and Ehab and another array construction task题解的更多相关文章

  1. CF959D Mahmoud and Ehab and another array construction task 数学

    Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same l ...

  2. codeforces-473D Mahmoud and Ehab and another array construction task (素数筛法+贪心)

    题目传送门 题目大意:先提供一个数组,让你造一个数组,这个数组的要求是 1 各元素之间都互质  2  字典序大于等于原数组  3 每一个元素都大于2 思路: 1.两个数互质的意思就是没有公因子.所以每 ...

  3. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  4. D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学

    D. Mahmoud and Ehab and another array construction task 因子分解模板 题意 给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!= ...

  5. Codeforces 959 D Mahmoud and Ehab and another array construction task

    Discription Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of ...

  6. [CF959F]Mahmoud and Ehab and yet another xor task题解

    搞n个线性基,然后每次在上一次的基础上插入读入的数,前缀和线性基,或者说珂持久化线性基. 然后一个num数组记录当时线性基里有多少数 然后每次前缀操作一下就珂以了 代码 #include <cs ...

  7. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  8. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  9. 959F - Mahmoud and Ehab and yet another xor task xor+dp(递推形)+离线

    959F - Mahmoud and Ehab and yet another xor task xor+dp+离线 题意 给出 n个值和q个询问,询问l,x,表示前l个数字子序列的异或和为x的子序列 ...

随机推荐

  1. SpringMvc @ModelAttribute 的用法

    参考:Spring 3.x 企业应用开发实战   第15章:SpringMvc  页码:532 ModelAttribute 从字面上解释就是模型的属性. 对于MVC框架来说是模型数据是最重要的,因为 ...

  2. 记2018最后一次问题诊断-Spark on Yarn所有任务运行失败

    2018的最后一个工作日,是在调式和诊断问题的过程中度过,原本可以按时下班,毕竟最后一天了,然鹅,确是一直苦苦挣扎. 废话不多说,先描述一下问题:有一套大数据环境,是CDH版本的,总共4台机子,我们的 ...

  3. vue组件父与子通信-登录窗口

    一.组件间通信(父组件    -->  子组件)步骤:①父组件在调用子组件 传值 <child-component myValue="123"> </chi ...

  4. 【ABAP系列】SAP VA02修改销售订单的BAPI举例

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP VA02修改销售订单的B ...

  5. 简述移动端与PC端的区别

    1.移动端与PC端的区别 PC考虑的是浏览器的兼容性,而移动端开发考虑的更多的是手机兼容性,因为目前不管是android手机还是ios手机,一般浏览器使用的都是webkit内核,所以说做移动端开发,更 ...

  6. Win10不能远程其他远程计算机的解决办法

    Win10不能远程其他远程计算机的解决办法   转自: https://blog.csdn.net/qq_38197830/article/details/69488236 首先打开控制面板——> ...

  7. js转换后台接受的日期格式

    var html = "--";if(data.createTime!=null&&data.createTime!=""){ Date.pro ...

  8. java_第一年_JDBC(6)

    DataBaseMetaData对象:由Connection.getDataBaseMetaData()方法获得,可以用来获取数据库的元数据,提供的方法有: getURL():返回一个String类, ...

  9. 本地SVN服务器的搭建(WINDOWS环境)

    1.下载安装 VISUALSVN SERVER 1.1下载地址:https://www.visualsvn.com/server/download/ 1.2下载完成后,双击安装. 2.下载安装 Tor ...

  10. vue观察模式浅析

    以下是我对vue观察者模式的理解:github L6zt 加入tip 2018-10-14 最近又看到<js设计模式设计>书 推荐去搂搂不要对框架的偏见, 你真的了解jquery.angu ...