现在有一个长度为n的数列 n不超过4000 求出它的gcd生成set 生成方式是对<i,j> insert进去(a[i] ^ a[i+1] ... ^a[j]) i<=j

然而现在给你了set 规模m<=1000 求原数列或check不可行

可以想到set中的max数字一定是原数列中的max , min数字一定是所有数字的因子 然而这样就走不下去了,没法通过枚举n或者什么来确定是否存在

一通乱想之后想出来了奇妙的解法。。

解:最小的数字为x 那么原数列中所有的数字都是x的倍数 它们一旦和x进行了gcd的操作,就一定会变成x。。

所以。。若给出的set为 a[1] a[2] a[3] a[4]

只需要输出 a[1] x a[2] x a[3] x a[4] x .. 这样对于所有的1区间异或 要么是区间长度为1 gcd是本身 要么是区间中包含x,那么gcd直接下降到x。

int a[1050] ;

int main () {
int m = read() ;
rep(i,1,m) a[i] = read() ;
rep(i,2,m) {
if(a[i]%a[1]!=0) {
printf("-1\n") ; return 0 ;
}
}
printf("%d\n" , m*2) ;
rep(i,1,m) {
printf("%d %d" , a[i] , a[1]) ;
if(i==m) printf("\n") ; else printf(" ") ;
}
}

Codeforces Round #447 (Div. 2) C 构造的更多相关文章

  1. Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence【构造/GCD】

    C. Marco and GCD Sequence time limit per test 1 second memory limit per test 256 megabytes input sta ...

  2. Codeforces Round #272 (Div. 1) B 构造 math

    http://www.codeforces.com/contest/477/problem/C 题目大意:给你n个集合,每个集合里面有四个数字,他们的gcd是k,输出符合条件的集合中m,m为集合中最大 ...

  3. Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field 数学

    题目链接 题意:给你三个数n,m,k;让你构造出一个nm的矩阵,矩阵元素只有两个值(1,-1),且满足每行每列的乘积为k,问你多少个矩阵. 解法:首先,如果n,m奇偶不同,且k=-1时,必然无解: 设 ...

  4. Codeforces Round #447 (Div. 2) 题解 【ABCDE】

    BC都被hack的人生,痛苦. 下面是题解的表演时间: A. QAQ "QAQ" is a word to denote an expression of crying. Imag ...

  5. Codeforces Round #447 (Div. 2)

    我感觉这场CF还是比较毒的,虽然我上分了... Problem A  QAQ 题目大意:给你一个由小写字母构成的字符串,问你里面有多少个QAQ. 思路:找字符串中的A然后找两边的Q即可,可以枚举找Q, ...

  6. 题解——Codeforces Round #508 (Div. 2) T2 (构造)

    按照题意构造集合即可 注意无解情况的判断 #include <cstdio> #include <algorithm> #include <cstring> #in ...

  7. Codeforces Round #447 (Div. 2) 题解

    A.很水的题目,3个for循环就可以了 #include <iostream> #include <cstdio> #include <cstring> using ...

  8. CF1103C Johnny Solving (Codeforces Round #534 (Div. 1)) 思维+构造

    题目传送门 https://codeforces.com/contest/1103/problem/C 题解 这个题还算一个有难度的不错的题目吧. 题目给出了两种回答方式: 找出一条长度 \(\geq ...

  9. Codeforces Round #604 (Div. 2)D(构造)

    构造,枚举起点,如果一个序列成立,那么将它reverse依然成立,所以两个方向(从小到大或从大到小)没有区别,选定一个方向进行探测,直到探测不到以后回头,只要所给数据能成立,那么能探测进去就能探测出来 ...

随机推荐

  1. 【BZOJ1367】[Baltic2004]sequence 左偏树

    [BZOJ1367][Baltic2004]sequence Description Input Output 一个整数R Sample Input 7 9 4 8 20 14 15 18 Sampl ...

  2. 10013: An attempt was made to access a socket in a way forbidden by its access permissions

    nginx的error.log日志报错: 2018/01/25 11:55:22 [emerg] 3380#15488: bind() to 0.0.0.0:20003 failed (10013: ...

  3. [Algorithms] Counting Sort

    Counting sort is a linear time sorting algorithm. It is used when all the numbers fall in a fixed ra ...

  4. Plist文件介绍

    开发IOS遇到数据,这里专门做frame sprite数据说明 plist plist是property list的缩写.plist中包括一些命名值和使用Core  Foundation类型创建的值的 ...

  5. PAT 1016 Phone Bills(模拟)

    1016. Phone Bills (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A long-di ...

  6. CodeForces 157A Game Outcome

    A. Game Outcome time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  7. 使用maven搭建SSM框架

    使用maven搭建SSM框架,首先得准备好maven环境. 搭建maven环境 第一步:下载maven http://maven.apache.org/download.cgi 下载后解压就可以了. ...

  8. event chrome firefox 获取点击对象的 id 类

    <!doctype html><html lang="en"><head> <meta charset="UTF-8" ...

  9. Spring 框架的JDBC模板技术

    1. 概述 Spring 框架提供了很多持久层的模板类来简化编程; Spring 框架提供的JDBC模板类: JdbcTemplate 类; Spring 框架提供的整合 Hibernate 框架的模 ...

  10. mybatis框架(三)

    mybatis框架