2301. Dividing the Pirate Hoard

单点时限: 2.0 sec

内存限制: 256 MB

After raiding an island N pirates end up with M coins. After the raid everybody gathers coins and puts them together in a community pile, to be divided the next day. During the night one pirate decides to take his share himself. He sneaks his way to the hoard and divides the M coins into N equal piles, with K coins left over. He keeps the extra K coins for himself, hides his pile of coins, and puts the other piles of coins back into a single pile. The other pirates then do the same thing one at a time, each dividing the remaining coins into N piles, taking one pile, and keeping any extra coins to keep the remaining piles even.

Given the number of pirates and coins, find out how many coins each pirate will have his own hidden pile (his equal-sized pile plus remaining coins) and how many coins are left in the community pile at the end of the night.

输入格式

The input will be the number of coins, followed by the number of pirates.

输出格式

The output should be the number of coins received by each pirate from largest to smallest (separated by spaces), followed by the total number of coins remaining in the hoard on a second line.

样例

Input
12 2
/*
10 3
*/
Output
6 3
3
/*
4 2 2
2
*/

78 人解决,93 人已尝试。

99 份提交通过,共有 154 份提交。

2.6 EMB 奖励。

创建: 15 年,8 月前.

修改: 6 年,7 月前.

最后提交: 8 月,2 周前.

来源: 2007 Maryland High-school Programming Contest

题目标签