#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[1100];
int b[1100];
int gcd(int x,int y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
int main()
{
int n,i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int k=0;
for(i=0;i<n-1;i++)
{
if(gcd(a[i],a[i+1])==1)
{
b[k++]=a[i];
}
else
{
b[k++]=a[i];
b[k++]=1;
}
}
b[k++]=a[n-1];
printf("%d\n",k-n);
for(i=0;i<k-1;i++)
{
printf("%d ",b[i]);
}
printf("%d\n",b[k-1]);
return 0;
}
CodeForces 660A Co-prime Array (互质队列)
最新推荐文章于 2020-05-18 09:45:38 发布