日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Educational Codeforces Round 11A. Co-prime Array 数学

發(fā)布時(shí)間:2025/5/22 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Educational Codeforces Round 11A. Co-prime Array 数学 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

地址:http://codeforces.com/contest/660/problem/A

題目:

A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard input output 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.

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?kelements to it.

If there are multiple answers you can print any one of them.

Example input 3
2 7 28 output 1
2 7 9 28

?思路:互質(zhì)是兩個(gè)數(shù)的最大公約數(shù)為1,即gcd(a,b)=1;

  如果相鄰兩個(gè)數(shù)不是互質(zhì)的話,插個(gè)1就好了(比賽時(shí)沒想到1,插得是1—100內(nèi)某一質(zhì)數(shù),(因?yàn)閤<10^9,所以100內(nèi)的質(zhì)數(shù)絕對可以,因?yàn)槌朔e大于最大取值范圍了)

  代碼:

?

1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cmath> 5 #include <cstring> 6 #include <queue> 7 #include <stack> 8 #include <map> 9 #include <vector> 10 11 #define PI acos((double)-1) 12 #define E exp(double(1)) 13 using namespace std; 14 15 int a[1010]; 16 int b[5000]; 17 int prime[17] = { 0,7,13,19,23,31,37,41,43,47,53,59,61,67,71,73,79 }; 18 19 int is_coprime(int a, int b) 20 { 21 int t = 1; 22 while (t) 23 { 24 if (b == 1) 25 return 1; 26 t = a %b; 27 a = b; 28 b = t; 29 } 30 return 0; 31 } 32 33 int main(void) 34 { 35 int n, k; 36 while (scanf("%d", &n) == 1) 37 { 38 k = 1; 39 memset(b, 0, sizeof(b)); 40 for (int i = 1; i <= n; i++) 41 scanf("%d", &a[i]); 42 for (int i = 1; i<n; i++) 43 { 44 if (is_coprime(a[i], a[i + 1])) 45 { 46 b[k++] = a[i]; 47 } 48 else 49 { 50 b[k++] = a[i]; 51 for (int j = 1; j <= 16; j++) 52 if (is_coprime(a[i], prime[j]) && is_coprime(a[i + 1], prime[j])) 53 { 54 b[k++] = prime[j]; 55 break; 56 } 57 } 58 } 59 b[k] = a[n]; 60 cout << k - n << endl; 61 for (int i = 1; i<k; i++) 62 printf("%d ", b[i]); 63 printf("%d\n", b[k]); 64 } 65 return 0; 66 } View Code

?

轉(zhuǎn)載于:https://www.cnblogs.com/weeping/p/5371872.html

總結(jié)

以上是生活随笔為你收集整理的Educational Codeforces Round 11A. Co-prime Array 数学的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 中文字幕天堂av | 狠狠躁18三区二区一区传媒剧情 | 后进极品白嫩翘臀在线视频 | 在线观看第一页 | 国产91av在线播放 | 久久一区二| 欧美日韩中文字幕 | 日韩免费a | 午夜影院免费体验区 | 日韩在线天堂 | 亚洲色图偷 | 人人人插| 国产精品久久一区 | 黄色片免费观看 | av导航网站 | 天堂在线中文在线 | 丁香花电影高清在线阅读免费 | 噼里啪啦免费高清看 | 久久久久久爱 | 中文字幕av亚洲精品一部二部 | 色姑娘av | 欧美第一页 | 综合色站导航 | 亚洲中文字幕无码不卡电影 | 国产伦精品一区二区免费 | 国产黄色片在线免费观看 | av成人动漫 | 亚洲综合激情另类小说区 | 亚洲一区二区在线观看视频 | 欧美偷拍一区二区 | 日韩亚洲国产欧美 | 91精品国产乱码久久久张津瑜 | 黑丝美女啪啪 | 免费一级特黄3大片视频 | 在线观看不卡的av | 久免费一级suv好看的国产 | 最新av在线网站 | 自拍av在线 | 午夜一二三| 午夜影院在线视频 | 成人91免费视频 | 综合人人 | 五月天狠狠操 | 成人女同在线观看 | 国产又粗又猛又爽视频 | 天天爽夜夜春 | 黄视频免费观看 | 欧美乱论视频 | 特色黄色片| 四级黄色片| 久久不卡视频 | www九九九| 欧美精品久久久久久久多人混战 | 精品欧美一区二区久久久 | 中文字幕第315页 | 97国产精品视频人人做人人爱 | 亚洲天堂男人网 | 黄色在线视频观看 | 色在线播放 | 鲁鲁在线 | 豆豆色成人网 | 91爱| 一区二区视频免费观看 | 中文字幕亚洲一区二区三区五十路 | 奶罩不戴乳罩邻居hd播放 | 在线观看v片 | 韩国电影一区二区三区 | av永久免费观看 | 黄色一级在线观看 | 免费国产视频在线观看 | 色视频免费在线观看 | www.久久久久久久久久 | 国产精品扒开腿做爽爽爽视频 | 久久911 | 亚洲第一黄网 | 丁香六月综合激情 | 久久精品福利视频 | 五月伊人婷婷 | 久久不卡区| 国产一区二区在线免费观看视频 | 日韩精品亚洲精品 | 国产激情一区二区三区四区 | 在线观看涩涩 | 精品日本一区二区三区 | 日韩二区在线观看 | 伊人久久大香线蕉综合网站 | 涩av| 精品人妻无码专区在线 | 色呦呦一区 | 精品无码久久久久 | 在线播放波多野结衣 | 国产成a人亚洲精v品无码 | 午夜不卡久久精品无码免费 | 1024中文字幕| 午夜国产小视频 | 久久欧美 | 国产资源第一页 | 亚洲国产精品一区 | 欧美性视频网站 |