#GL0000299. Định lý số dư Trung Hoa tổng quát (General Chinese Remainder)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Định lý số dư Trung Hoa tổng quát (General Chinese Remainder)
General Chinese Remainder
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Consider the two congruences with positive moduli:
Unlike the coprime case, and need not be relatively prime. Thus, a common solution may not exist.
When a solution exists, all solutions differ by multiples of . Find the unique representative satisfying and output it together with . Otherwise, print the specified impossibility message.
Input
One line containing the four integers , in this order.
Output
If a solution exists, print separated by one space. If none exists, print exactly no solution.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Examples 1
Input
2 4 4 6
Output
10 12
Explanation
The number leaves remainder modulo and remainder modulo . The combined modulus is .
Examples 2
Input
1 4 2 6
Output
no solution
Explanation
Numbers congruent to modulo are odd, while those congruent to modulo are even. No common solution exists.