Gru is Handing Out Bananas
All submissions for this problem are available.Gru wants to distribute $N$ bananas to $K$ minions on his birthday. Gru does not like to just give everyone the same number of bananas, so instead, he wants to distribute bananas in such a way that each minion gets a $distinct$ amount of bananas. That is, no two minions should get the same number of bananas. Gru also loves $gcd$. The higher the $gcd$, the happier Gru and the minions get. So help Gru in distributing the bananas in such a way that each Minion gets a distinct amount of bananas and gcd of this distribution is highest possible. Output this maximum gcd. If such a distribution is not possible output $-1$. Note: You have to distribute $all$ $N$ bananas. ###Input: - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase consists of a single line of input, which has two integers: $N, K$. ###Output: For each testcase, output in a single line the maximum gcd or -1. ###Constraints - $1 \leq T \leq 100$ - $1 \leq N, K \leq 10^9$ ###Sample Input: 1 6 3 ###Sample Output: 1 ###EXPLANATION: The only possible distribution is $[1, 2, 3]$. So the answer is 1.
|Tags||factorization, gcd, guptaishita24, plit2020|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.