Solution 1: accepted 64ms 10%
|
|
Solution 2: accepted 46ms 69%
Cost of coins: 1+2+3+…+k = k(1+k)/2
Calculate the maximum of k where k(1+k) <= 2n
(0 <= k < n)
|
|
Alternative from this post
|
|
Solution 3
We have many math solutions.
|
|
Cost of coins: 1+2+3+…+k = k(1+k)/2
Calculate the maximum of k where k(1+k) <= 2n
(0 <= k < n)
|
|
Alternative from this post
|
|
We have many math solutions.