CodeForces 660A
Description
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.
Input
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.
Output
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.
我不想说,本来可以一次a掉的 硬是搞了好几次,不需要加数的时候0也要输出,
只要判断相邻是否互质,否的时候在中间插入1,因为1和任何数都互质,
英语是硬伤
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstdio>
#include<cstring>
using namespace std;
int fun(int m,int n)
{
if(m<n)
{
n=m+n;
m=n-m;
n=n-m;
}
int t;
while(m%n!=)
{
t=n;
n=m%n;
m=t;
}
return n;
}
int main()
{
queue<int>Q;
int a[],b[];
int n,t;
int i,j;
while(cin>>n)
{
t=;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(i=;i<=n;i++)
{
cin>>a[i];
}
b[t]=a[];
for(j=;j<=n;j++)
{
if(fun(b[t],a[j])==)
{
b[++t]=a[j];
}
else
{
b[++t]=;
b[++t]=a[j];
}
}
cout<<t-n<<endl;
cout<<b[];
for(i=;i<=t;i++)
cout<<" "<<b[i];
cout<<endl; }
return ;
}
Sample Input
3
2 7 28
1
2 7 9 28
CodeForces 660A的更多相关文章
- Codeforces 660A. Co-prime Array 最大公约数
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- codeforces 660A A. Co-prime Array(水题)
题目链接: A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input stand ...
- CodeForces 660A Co-prime Array
水题.放个1就可以了.暴力的找数字也是很快的. #include<cstdio> #include<cstring> #include<cmath> #includ ...
- Co-prime Array&&Seating On Bus(两道水题)
Co-prime Array Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Su ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- Java 基本的递归写法
1.首先我们得有一个树状结构的表,类似这种结构.必须得有 id,pid 其他的根据需要来. 我们叫它treeTbl表吧.这里pid为0的表示是顶级节点. 2.接着select * from tree ...
- Redis配置文件各项参数说明及性能调优
Redis配置文件参数说明: 1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonize no 2. 当Redis以守护进程方式运行时,Redis默 ...
- SqlServer 导出指定表数据 生成Insert脚本
版权声明:本文为博主原创文章,未经博主允许不得转载.
- uni-app的专属强大自适应单位upx,但是这个这是一个大坑,不能动态赋值解决办法
uni-app 使用 upx 作为默认尺寸单位, upx 是相对于基准宽度的单位,可以根据屏幕宽度进行自适应.uni-app 规定屏幕基准宽度750upx. 开发者可以通过设计稿基准宽度计算页面元素 ...
- phpStudy 升级 MySQL版本
1:停止phpStudy ,Mysql 服务;删除Mysql 文件夹 替换为新版本的Mysql 2:复制一份 my-default.ini,改名 my.ini ,打开,在最后面加上: basedir= ...
- spring cloud(五) hystrix
开启feign 熔断 hystrix 整合hystrix-dashboard监控面板 1. 服务调用者boot工程 pom引入依赖 <!-- hystrix-dashboard 监控依赖 ...
- [IOI2007]矿工配餐
状态是f[i][a][b][c][d]表示第i个餐车,1号矿洞最近两顿是a,b,2号矿洞最近两顿是c,d. 给的空间是16MB,滚动数组滚动了第一维就行了 (给的变量是char是因为这个不超过256, ...
- MongoDB之Too many open files
在Linux下有时会遇到cannot open /dev/urandom Too many open files的问题.其实Linux是有文件句柄限制的,而且Linux默认一般都是1024(阿里云主机 ...
- EurekaLog是什么鬼?
D的all工程文件打开后,莫名其妙就处于等待打开状态.因为最后一次调整是安装了RO9.0.所以一直怀疑是RO的原因.再加上win7授权问题,安装RO一直不顺当.所以折腾的时间最多. 其他把RO全部卸载 ...
- 【hihocoder 1476】矩形计数
[题目链接]:http://hihocoder.com/problemset/problem/1476 [题意] [题解] 首先不考虑黑格子,计算出一共有多少个矩形: 枚举矩形的大小r×c,这样大小的 ...