C. Vulnerable Kerbals

Codeforces
IDCF800C
Time2000ms
Memory256MB
Difficulty
constructive algorithmsmathnumber theory
You are given an integer _m_, and a list of _n_ distinct integers between 0 and _m_ - 1. You would like to construct a sequence satisfying the properties: * Each element is an integer between 0 and _m_ - 1, inclusive. * All prefix products of the sequence modulo _m_ are distinct. * No prefix product modulo _m_ appears as an element of the input list. * The length of the sequence is maximized. Construct any sequence satisfying the properties above. ## Input The first line of input contains two integers _n_ and _m_ (0 ≤ _n_ < _m_ ≤ 200 000) — the number of forbidden prefix products and the modulus. If _n_ is non-zero, the next line of input contains _n_ distinct integers between 0 and _m_ - 1, the forbidden prefix products. If _n_ is zero, this line doesn't exist. ## Output On the first line, print the number _k_, denoting the length of your sequence. On the second line, print _k_ space separated integers, denoting your sequence. [samples] ## Note For the first case, the prefix products of this sequence modulo _m_ are \[1, 2, 3, 4, 0\]. For the second case, the prefix products of this sequence modulo _m_ are \[3, 7, 4, 6, 8, 0\].
Samples
Input #1
0 5
Output #1
5
1 2 4 3 0
Input #2
3 10
2 9 1
Output #2
6
3 9 2 9 8 0
API Response (JSON)
{
  "problem": {
    "name": "C. Vulnerable Kerbals",
    "description": {
      "content": "You are given an integer _m_, and a list of _n_ distinct integers between 0 and _m_ - 1. You would like to construct a sequence satisfying the properties: *   Each element is an integer between 0 an",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF800C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an integer _m_, and a list of _n_ distinct integers between 0 and _m_ - 1.\n\nYou would like to construct a sequence satisfying the properties:\n\n*   Each element is an integer between 0 an...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments