PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000083. Neko tối ưu BCNN sau khi cộng (Neko does Maths)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Neko tối ưu BCNN sau khi cộng (Neko does Maths)
Neko does Maths
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Neko has positive integers and . Choose a nonnegative integer to add to both numbers, minimizing . If several values yield the same minimum LCM, choose the smallest such .
Input
One line containing integers and .
Output
Print the smallest nonnegative yielding the minimum LCM.
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Input
6 10
Output
2
Explanation
For the values become and with LCM . For the LCM is , while for it is . No gives an LCM smaller than .