#GL0000306. Mã bí mật (Code Feat)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mã bí mật (Code Feat)
Code Feat
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Agent Bauer must deactivate a bomb protected by a security code that is a strictly positive integer. CTU analysts have obtained several clues describing which remainders are allowed when dividing the code by a certain integer.
A clue consists of an integer and a set of distinct remainders . The code must have a remainder belonging to this set when divided by . The moduli of different clues are pairwise coprime.
Call a positive integer valid if it satisfies all clues simultaneously. There are infinitely many valid integers, but the experts want to examine the smallest ones first.
Find exactly the smallest valid positive integers and print them in increasing order, each exactly once.
Input
- The first line contains integers , the number of clues and requested answers.
- For each , one line contains , followed by exactly distinct integers , the allowed remainders modulo .
Output
Print exactly lines. Line contains the -th smallest valid positive integer, so the values must be strictly increasing.
Subtasks
- Subtask 1 (20 points): , ; ; ; , distinct remainders within each clue; for all ; .
- Subtask 2 (30 points): , ; ; ; , distinct remainders within each clue; for all ; .
- Subtask 3 (50 points): , ; ; ; , distinct remainders within each clue; for all ; .
Examples
Example 1
Input
3 2
2 1 1
5 2 0 3
3 2 1 2
Output
5
13
Explanation
The remainders of modulo are , respectively. The remainders of are . Both satisfy every clue. Every positive integer below , and every integer from through , violates at least one clue, so these are the two smallest answers.
Example 2
Input
1 3
4 2 0 2
Output
2
4
6
Explanation
The allowed remainders modulo are and . The valid positive integers start with ; thus the first three are .