Co-prime Array&&Seating On Bus(两道水题)

时间:2023-03-17 22:30:40
Co-prime Array&&Seating On Bus(两道水题)
 Co-prime Array

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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 addingk elements to it.

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

Sample Input

Input
3 2 7 28
Output
1 2 7 9 28
题意:让加最少的数使成为互质集合:相邻两个数互质;。。。水,1与任何数互质
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN = ;
int num[MAXN];
int ans[MAXN << ];
int gcd(int a,int b){
return b == ? a : gcd(b, a%b);
}
/*
int find(int a, int b){
for(int i )
}
*/
int main(){
int N;
while(~scanf("%d", &N)){
int tp = ;
for(int i = ; i <= N; i++){
scanf("%d", num + i);
}
ans[tp++] = num[];
for(int i = ; i <= N; i++){
if(gcd(num[i], num[i - ]) != ){
ans[tp++] = ;
ans[tp++] = num[i];
}
else ans[tp++] = num[i];
}
printf("%d\n", tp - N);
for(int i = ; i < tp; i++){
if(i)printf(" ");
printf("%d", ans[i]);
}
puts("");
}
return ;
}
Seating On Bus

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.

Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:

1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.

After occupying all the window seats (for m > 2n) the non-window seats are occupied:

1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.

All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.

1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.

Co-prime Array&&Seating On Bus(两道水题)The seating for n = 9 and m = 36.

You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.

Input

The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.

Output

Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.

Sample Input

Input
2 7
Output
5 1 6 2 7 3 4
Input
9 36
Output
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
题意:坐公交车。。。水;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN = ;
int num[][MAXN];
int main(){
int n,m;
while(~scanf("%d%d",&n, &m)){
int tp = ;
for(int i = ; i <= n; i++){
num[][i] = ++tp;
num[][i] = ++tp;
}
for(int i = ; i <= n; i++){
num[][i] = ++tp;
num[][i] = ++tp;
}
int x = ;
for(int i = ; i <= n; i++){
if(num[][i] <= m){
if(x)printf(" ");
printf("%d",num[][i]);
x++;
}
if(num[][i] <= m){
if(x)printf(" ");
printf("%d",num[][i]);
x++;
}
if(num[][i] <= m){
if(x)printf(" ");
printf("%d",num[][i]);
x++;
}
if(num[][i] <= m){
if(x)printf(" ");
printf("%d",num[][i]);
x++;
} }
puts("");
}
return ;
}