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 ...
随机推荐
- javascript 关于弹出新页面始终在正中央方法
记录一个关于弹出新页面始终在正中央方法 function openwindow(url, name, iWidth, iHeight) { var url; ...
- C语言-字符串
问题: 给出的区分大小写的字母字符的字符串,找到最大的字符串X,或者为X,或者其逆可以找到任何给定的字符串的子串 输入: 输入文件的第一行包含一个整数t(1 < = t < = 10),测 ...
- 关于PM的认识
1 我眼中的PM 1.1 人云“一个管理,半个专家”,我说“一个管理,两个专家” 如今,我发现我们不得不面对这样一个现实——角色兼职.我习惯上把项目分为三类:性命攸关的项目(涉及到人身安全的项目,如铁 ...
- 缷载vs2015后项目不能加载问题
当加载项目时出现MSBuildToolsPath is not specified for the ToolsVersion "14.0" defined at "HKE ...
- java 中的CountDownLatch
直接使用thread可以使用thread和wait notify 实现顺序执行 线程池中可以使用CountDownLatch 进行顺序执行 package com.test; import java. ...
- IIS 配置错误:不能在此路径中使用此配置节。如果在父级别上锁定了该节,便会出现这种情况。 HTTP 错误 500.19
因为 IIS 7 采用了更安全的 web.config 管理机制,默认情况下会锁住配置项不允许更改.运行命令行 %windir%\system32\inetsrv\appcmd unlock conf ...
- C#下的摄像机标定
前言:计算机视觉的基本任务之一是从摄像机获取的图像信息出发计算三维空间中物体的几何信息,并由此重建和识别物体,而空间物体表面某点的三维几何位置与其在图像中对应点之间的相互关系是由摄像机成像的几何模型决 ...
- Java泛型【转】
一. 泛型概念的提出(为什么需要泛型)? 首先,我们看下下面这段简短的代码: public class GenericTest { public static void main(String[] a ...
- 基于EasyNVR二次开发实现自己的摄像机IPC/NVR无插件化直播解决方案
在之前的博客中<基于EasyNVR实现RTSP/Onvif监控摄像头Web无插件化直播监控>,我们已经比较多的描述EasyNVR所实现的功能,这些也在方案地址:http://www.eas ...
- regularexpression_action
re.compile('"ssid":"[^"]*"}',re.MULTILINE) regex ,str_= re.compile('"s ...