您的位置:首页 > 其它

codeforces 660A A. Co-prime Array(水题)

2016-04-09 01:03 323 查看
题目链接:

A.Co-primeArray

timelimitpertest
1second

memorylimitpertest
256megabytes

input
standardinput

output
standardoutput

Youaregivenanarrayofnelements,youmustmakeitaco-primearrayinasfewmovesaspossible.

Ineachmoveyoucaninsertanypositiveintegralnumberyouwantnotgreaterthan109inanyplaceinthearray.

Anarrayisco-primeifanytwoadjacentnumbersofitareco-prime.

Inthenumbertheory,twointegersaandbaresaidtobeco-primeiftheonlypositiveintegerthatdividesbothofthemis1.

Input
Thefirstlinecontainsintegern(1 ≤ n ≤ 1000)—thenumberofelementsinthegivenarray.

Thesecondlinecontainsnintegersai(1 ≤ ai ≤ 109)—theelementsofthearraya.

Output
Printintegerkonthefirstline—theleastnumberofelementsneededtoaddtothearrayatomakeitco-prime.

Thesecondlineshouldcontainn + kintegersaj—theelementsofthearrayaafteraddingkelementstoit.Notethatthenewarrayshouldbeco-prime,soanytwoadjacentvaluesshouldbeco-prime.Alsothenewarrayshouldbegotfromtheoriginalarrayabyaddingkelementstoit.

Iftherearemultipleanswersyoucanprintanyoneofthem.

Example

input
3
2728


output
1
27928

题意:

给一个数组,问插入多少个数字才能使相邻的两个数互质;

思路:

暴力找呗,找到的放队列里,最后输出不就好了;

AC代码:


/*
2014300227660A-7GNUC++11Accepted15ms2188KB
*/

#include<bits/stdc++.h>
usingnamespacestd;
constintN=1e5+4;
typedeflonglongll;
constdoublePI=acos(-1.0);
intn,a[3000];
intgcd(intx,inty)
{
if(y==0)returnx;
returngcd(y,x%y);
}
queue<int>qu;
intmain()
{
scanf("%d",&n);
for(inti=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
intnum=0;
for(inti=1;i<n;i++)
{
qu.push(a[i]);
if(gcd(a[i],a[i+1])>1)
{


qu.push(1);
num++;
}
}
qu.push(a
);
printf("%d\n",num);
while(!qu.empty())
{
printf("%d",qu.front());
qu.pop();
}


return0;
}


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: