现在有一个长度为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. [hihoCoder] 拓扑排序·一

    The hints of the problem has given detailed information to implement the topological sorting algorit ...

  2. 用Python xlwt建立excel表格

    1.下载xlwt的Python库 (This is a library for developers to use to generate spreadsheet files compatible w ...

  3. 第5章 IDA Pro实验题

    Question: 1.DLLMain的地址是什么? 2.使用import窗口并浏览到gethostbyname,导入函数定位到什么位置 3.有多少函数调用了gethostbyname? 4.将精力放 ...

  4. Checksum 磁盘扇区故障检测

    w https://en.wikipedia.org/wiki/Checksum https://zh.wikipedia.org/wiki/校验和 A checksum is a small-siz ...

  5. jsp tutorial

    http://blog.csdn.net/JavaEETeacher/article/details/1932447

  6. Storm-源码分析汇总

    Storm Features Storm 简介 Storm Topology的并发度 Storm - Guaranteeing message processing Storm - Transacti ...

  7. mysql主从同步因断电产生的不能同步问题

    偶尔因为断电导致mysql slave 出现复制错误“Could not parse relay log event entry” Could not parse relay log event en ...

  8. Runtime Error! R6025-pure virtual function call 问题怎么解决

    一.故障现象:1.360软件的木马查杀.漏洞修复等组件不能使用,提示runtime error2.暴风影音等很多软件不能正常使用3.设备管理器不能打开,提示“MMC 不能打开文件”4.部分https安 ...

  9. 基于vue + typescrpt +vuecli 搭建开发环境

    打算学习typeScript与vue集成,先放几个链接,留着自己学习用,后续自己写使用新的~ https://segmentfault.com/a/1190000013676663 https://j ...

  10. Django - 权限分配、权限组件与CRM整合

    一.权限分配 需求:为用户分配角色,为角色分配权限,如下图效果: 1.视图代码: from django.shortcuts import render from django.http import ...