No.136 Yet Another GCD Problem
Problem Statement
For an array $A$ of positive integers, when the sum of $A$ is exactly $x$, we call $A$ a partition of $x$.
For an array $A$ of integers, we define $\gcd(A) = \gcd(A_1,A_2,\ldots,A_{|A|})$.
You are given integers $N, K$. Over all partitions $A$ of $N$ satisfying $2 \le |A| \le K$, maximize $\gcd(A)$.
Input
N K
The integers $N, K$ ($2 \le N \le 10^5$, $2 \le K \le 10^5$) are given on one line, separated by a space.
Output
Among all $A$ satisfying the conditions in the problem statement, print on one line the value $\gcd(A)$ of an $A$ for which $\gcd(A)$ is maximum.
Sample
Sample 1
Input
21 2
Output
7
For example, if $A = [7,14]$, then $A$ is a partition of $21$, and the greatest common divisor of the elements of $A$ is $\operatorname{gcd}(7,14) = 7$.
Sample 2
Input
23 100000
Output
1
No matter how 23 is split into an array of length 2 or more, the greatest common divisor of its elements is 1.
Sample 3
Input
100 2
Output
50
$A = [50,50]$ is the only partition whose elements have a greatest common divisor of 50.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
anta