PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000071. Phân hoạch để tối đa ƯCLN (Partition)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phân hoạch để tối đa ƯCLN (Partition)
Partition
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given positive integers and . Consider all sequences of exactly positive integers whose sum is . For each sequence, take the greatest common divisor (GCD) of all its entries. Find the maximum possible GCD over all such sequences. Print only the maximum value; you need not construct the sequence.
Input
A line containing two integers and .
Output
Print one integer, the maximum possible GCD.
Subtasks
-
Subtask 1 (20 points): , .
-
Subtask 2 (30 points): , .
-
Subtask 3 (50 points): , .
Examples
Input
3 14
Output
2
Explanation
The sequence has three positive entries, sums to , and has GCD . Any common divisor must divide and satisfy . Among the divisors , the largest feasible one is .