codeforces 660A A. Co-prime Array(水题)
题目链接:
1 second
256 megabytes
standard input
standard output
You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it.
If there are multiple answers you can print any one of them.
3
2 7 28
1
2 7 9 28 题意: 给一个数组,问插入多少个数字才能使相邻的两个数互质; 思路: 暴力找呗,找到的放队列里,最后输出不就好了; AC代码:
/*
2014300227 660A - 7 GNU C++11 Accepted 15 ms 2188 KB
*/
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+4;
typedef long long ll;
const double PI=acos(-1.0);
int n,a[3000];
int gcd(int x,int y)
{
if(y==0)return x;
return gcd(y,x%y);
}
queue<int>qu;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
int num=0;
for(int i=1;i<n;i++)
{
qu.push(a[i]);
if(gcd(a[i],a[i+1])>1)
{
qu.push(1);
num++;
}
}
qu.push(a[n]);
printf("%d\n",num);
while(!qu.empty())
{
printf("%d ",qu.front());
qu.pop();
}
return 0;
}
codeforces 660A A. Co-prime Array(水题)的更多相关文章
- Educational Codeforces Round 11 A. Co-prime Array 水题
A. Co-prime Array 题目连接: http://www.codeforces.com/contest/660/problem/A Description You are given an ...
- CF451B Sort the Array 水题
Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- hdu 5532 Almost Sorted Array (水题)
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
- Codeforces - 1194B - Yet Another Crosses Problem - 水题
https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...
随机推荐
- js:string转int
http://blog.csdn.net/leidengyan/article/details/5503594 <script> var str='1250' ; aler ...
- Oracle 在Drop表时的Cascade Constraints
http://hi.baidu.com/rebooo/item/12b500b130022bf263388e69假设A为主表(既含有某一主键的表),B为从表(即引用了A的主键作为外键).则当删除A表时 ...
- C# 请求Web Api 接口,返回的json数据直接反序列化为实体类
须要的引用的dll类: Newtonsoft.Json.dll.System.Net.Http.dll.System.Net.Http.Formatting.dll Web Api接口为GET形式: ...
- mysql索引类型normal,unique,full text
normal:表示普通索引 unique:表示唯一的,不允许重复的索引,如果该字段信息保证不会重复例如身份证号用作索引时,可设置为unique full textl: 表示 全文搜索的索引. FULL ...
- 【设计模式】C++单例模式的几种写法——Java自动加载内部类对象,C++怎么破?
单例模式是最简单的设计模式,就让我像玩简单的游戏一样写下去吧. v1: 简单模式 和这个版本有过一面之缘,但不敢苟同. class Singleton { private: Singleton() { ...
- hibernate QBC查询
HQL运算符 QBC运算符 含义 = Restrictions.eq() 等于equal <> Restrictions.ne() 不等于not equal > Restrict ...
- PowerBuilder -- 日期
#PB自带日期相关函数 Date(...), DateTime(...), RelativeDate(...), Year(...), Month(...), Day(...), DaysAfter( ...
- 【PHP开发】远程文件(图片)下载
这一篇文章介绍的方法不算原创了,只是引用的别人的文章,加上自己的注释,因为接触php时间不长,所以尝试的东西比较多,自己加的注释也比较简单,php高手请略过. 我要用到远程下载图片,是在做微信公众平台 ...
- 真正入坑git
之前使用git一直用sourceTree可视化操作,直到今天刚好装不了sourceTree,所有只能苦逼的用git命令行了,真的一片空白,要做下笔记才行. 创建sshKey 创建ssh: ssh-ke ...
- NDK以及C语言基础语法(一)
一.什么是NDK? Native Development Kit (本地开发工具包): NDK中提供了一系列的工具,帮助我们快速开发C/C++的动态库,并能自动将so文件和java文件一起打包成apk ...