Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Dwarves and Coins

The Situation:

Several (M) dwarves have found a goblin's chest with N gold coins and have to divide them. Due to ancient rules governing the allocation of loot to pirates in order of seniority, the oldest dwarf should get one coin more than the next oldest dwarf, and so on, so that the youngest dwarf gets M-1 fewer coins than the oldest dwarf. Additionally, no dwarf has to pitch in any coins (ie no negative coins to any dwarfs)

Help the dwarves to divide the coins in this way, or tell them that this is impossible.

Winner's code must always answer correctly (this challenge is deterministic) and follow the general rules.

Input

You are given an integer N (3 ≤ N ≤ 1000) for number of coins and an integer M (3 ≤ M ≤ N) for number of dwarves, space-separated.

Output

If it is impossible to divide the coins in the way that dwarves want, print -1 (minus one). Otherwise, print the numbers of coins that each dwarf will receive, from oldest to youngest. Separate the numbers with spaces.

Samples:

input

3 3

output

2 1 0

input

9 3

output

4 3 2

input

7 3

output

-1

input

6 4

output

3 2 1 0

Answer*

Draft saved
Draft discarded
Cancel
2
  • \$\begingroup\$ Well done, it was instructive :) I changed my answer to strip the unnecessary space, but your trick to save the [::-1] is better than my solution. +1 \$\endgroup\$ Commented Apr 4, 2014 at 8:24
  • \$\begingroup\$ I may be missing something, but I counted 93 bytes instead of 94. \$\endgroup\$ Commented Sep 16, 2017 at 7:37

AltStyle によって変換されたページ (->オリジナル) /