PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000194. Ước lớn nhất không chia hết (Division)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ước lớn nhất không chia hết (Division)
Ước lớn nhất không chia hết (Division)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers , find the largest positive integer such that divides but does not divide .
Input
One line with and .
Output
Print the maximum valid .
Subtasks
-
Subtask 1 (20 points): ; .
-
Subtask 2 (30 points): ; .
-
Subtask 3 (50 points): ; .
Examples
Example 1
Input
12 6
Output
4
Explanation
Both and are divisible by . The largest divisor of that is not divisible by is .
Example 2
Input
10 4
Output
10
Explanation
Since is not divisible by , the greatest divisor of , namely itself, already satisfies the condition.
Example 3
Input
179 822
Output
179
Explanation
Since does not divide , the optimal answer is .