Error
|
|
---|---|
@Ibrahim Nash | 5761 |
@blackshadows | 5701 |
@akhayrutdinov | 5111 |
@mb1973 | 4989 |
@Quandray | 4944 |
@saiujwal13083 | 4506 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3516 |
@sushant_a | 3459 |
@verma_ji | 3341 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@aroranayan999 | 938 |
@bt8816103042 | 739 |
@SHOAIBVIJAPURE | 428 |
@codeantik | 412 |
@SherlockHolmes3 | 407 |
@neverevergiveup | 348 |
@mahlawatep | 347 |
@shalinibhataniya1097 | 343 |
@murarry3625 | 333 |
@saiujwal13083 | 326 |
@rohitanand | 314 |
Complete Leaderboard |
Given an integer N, the task is to find out M increasing numbers such that the sum of M numbers is equal to N and the GCD of these M numbers is maximum among all possible combinations (or series) of M numbers.
Note: If two or more such series are possible then return the series which has smallest first term.
Example 1:
Input: N = 24, M = 3
Output: 4 8 12
Explanation: (3, 6, 15) is also a series
of M numbers which sums to N, but gcd = 3
(4, 8, 12) has gcd = 4 which is the maximum
possible.
Example 2:
Input: N = 6, M = 4
Output: -1
Explanation: It is not possible as the
least GCD sequence will be 1+2+3+4 which
is greater then n, hence print -1.
Your Task:
You dont need to read input or print anything. Complete the function M_sequence() which takes N and M as input parameter and returns th series of M numbers and if there are no series exist returns -1.
Expected Time Complexity: O(sqrt(n))
Expected Auxiliary Space: O(n)
Constraints:
1 <= N <=105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes