Codeforces 894C C. Marco and GCD Sequence
来源:互联网 发布:人声翻译软件 编辑:程序博客网 时间:2024/05/18 00:27
题目大意:给你n个数,让你求出一个序列,满足对于任意的i和j,都能使gcd(ai,...,aj)可以得到n个数的一个
最小的数一定是对这n个数gcd得出的结果,如果不是就-1,是的话我们就在每两个元素之间插入这个最小的数即可
#include<iostream>#include<algorithm>using namespace std;const int maxn=1010;int num[maxn];int main(){int n;while(cin>>n){int gcd;for(int i=1;i<=n;i++){cin>>num[i];if(i==1) gcd=num[1];else gcd=__gcd(gcd,num[i]);}if(gcd!=num[1]){cout<<-1<<endl;}else{cout<<2*n-1<<endl;for(int i=1;i<=n;i++){if(i==n) cout<<num[i]<<endl;else cout<<num[i]<<' '<<num[1]<<' ';}}}}
阅读全文
0 0
- codeforces-894C Marco and GCD Sequence
- codeforces 864C Marco and GCD Sequence
- codeforces C. Marco and GCD Sequence
- Codeforces 894C C. Marco and GCD Sequence
- Codeforces 894C:Marco and GCD Sequence(构造)
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence 构造
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence (构造 贪心)
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence(构造,思路)
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence(构造)
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence 构造
- Marco and GCD Sequence
- CF-Marco and GCD Sequence
- Codeforces894C Marco and GCD Sequence
- Codeforces 798C Mike and gcd problem
- [绍棠] React Native开发错误警告处理总结
- intellij idea 常用命令(常更)
- 《剑指offer》刷题笔记(分解让复杂问题简单):字符串的排列
- excel文件已损坏,无法打开
- 图像生成与图像模型——颜色
- Codeforces 894C C. Marco and GCD Sequence
- 嵌入式软件
- Laravel获取所有的数据库表及结构
- 20多家银行加入“新加坡-香港”区块链贸易网络项目
- 纳斯达克研究如何在区块链上存储资产数据
- 澳大利亚政府为区块链能源项目拨款800万澳元
- AndroidStudio 快捷键
- DB2主键生成的方式
- MySQL安装后,如何找到my.ini文件以及修改编码方式