PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000298. Định lý số dư Trung Hoa (Chinese Remainder)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Định lý số dư Trung Hoa (Chinese Remainder)
Chinese Remainder
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Given four integers , consider the two congruences
It is guaranteed that . Therefore, exactly one integer in satisfies both congruences.
Find this and also output the common modulus .
Input
A single line containing , in that order.
Output
Print two space-separated integers: and .
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
Examples
Examples 1
Input
2 3 3 5
Output
8 15
Explanation
Since and , and all other solutions differ by a multiple of , the output is 8 15.
Examples 2
Input
0 7 3 5
Output
28 35
Explanation
The integer is divisible by and leaves remainder modulo . The combined modulus is .