#P8961. 「WHOI-4」ggcd

    ID: 9577 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数论Special JudgeO2优化素数判断,质数,筛法中国剩余定理 CRT

「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 yy of length nn and a positive integer mm, guaranteeing 0yi<m0 \le y_i < m. Please construct an array xx of the same length nn such that:

  1. xix_i is within the range of __int128.
  2. ximodm=yix_i \bmod m = y_i.
  3. gcd(x1,,xn)modm\gcd(|x_1|, \cdots, |x_n|) \bmod m is as large as possible.

Note that xix_i can be negative. In this case, m(xiyi)m \mid (x_i - y_i) and 0yi<m0 \le y_i < m.

Input Format

The first line contains two positive integers n,mn, m.

The next line contains nn non-negative integers, representing the values of ximodmx_i \bmod m.

Output Format

The first line contains a non-negative integer gg, representing the maximum possible value of gcd(x1,x2,,xn)modm\gcd(|x_1|, |x_2|, \cdots, |x_n|) \bmod m.

The next line contains nn integers, representing xix_i.

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 (3030 pts): mm is prime.

Subtask 2 (7070 pts): No special restrictions.

For all data, it is guaranteed that 2m1092 \le m \le 10^9 and 1n1061 \le n \le 10^6.

About Special Judge

For each test point:

If your output format is incorrect, you will get 00 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 xx does not match the given yy in the statement, you will get 00 points.

If your sequence xx does not match the gg you output, you will get 00 points.

If your gg is not the maximum, you will get 00 points.

Otherwise, you will get full points for that test point.

Translated by ChatGPT 5