#P8961. 「WHOI-4」ggcd
「WHOI-4」ggcd
Background
How to input and output __int128:
__int128 read() {
char c = getchar();
__int128 x = 0;
bool f = 0;
for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
if (f) x = -x;
return x;
}
void write(__int128 x, char c = '\0') {
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
if (c != '\0') putchar(c);
}
Problem Description
A new sample has been added to this problem. Please check it.
Little Y gives you an array of length and a positive integer , guaranteeing . Please construct an array of the same length such that:
- is within the range of
__int128. - .
- is as large as possible.
Note that can be negative. In this case, and .
Input Format
The first line contains two positive integers .
The next line contains non-negative integers, representing the values of .
Output Format
The first line contains a non-negative integer , representing the maximum possible value of .
The next line contains integers, representing .
1 10
4
6
-6
1 10
7
7
7
2 9
3 3
6
12 -6
10 7
1 2 3 4 5 6 0 1 2 3
6
36 30 24 18 12 6 42 -6 30 24
Hint
Constraints
This problem uses bundled testdata.
Subtask 1 ( pts): is prime.
Subtask 2 ( pts): No special restrictions.
For all data, it is guaranteed that and .
About Special Judge
For each test point:
If your output format is incorrect, you will get points.
If any number you output is not within the range of __int128, it may cause overflow, so you may not get the expected score.
If your sequence does not match the given in the statement, you will get points.
If your sequence does not match the you output, you will get points.
If your is not the maximum, you will get points.
Otherwise, you will get full points for that test point.
Translated by ChatGPT 5