QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22580. 数字の和を逆算する

Statistics

FJ と牛たちは頭を使うゲームを楽しんでいます。$1$ から $N$($1 \le N \le 10$)までの数をある順序で書き、隣り合う数を足して、数が 1 個少ない新しいリストを作ります。これを数が 1 個だけになるまで繰り返します。例えば、$N=4$ のとき、ゲームは次のように進むかもしれません。

3   1   2   4
  4   3   6
    7   9
     16

FJ に内緒で、牛たちはより難しいゲームを始めました。最後の合計と数 $N$ だけから、最初の数列を特定するゲームです。残念ながら、このゲームは FJ の暗算能力を少し超えています。

FJ がこのゲームをプレイして牛たちについていけるよう、プログラムを書いてください。

入力

  • 1 行目:空白で区切られた 2 つの整数、$N$ と最後の和。

出力

  • 1 行目:指定された和を生む、整数 $1..N$ の並び方。複数の解がある場合は、辞書順で最小のもの、すなわち小さい数を先に置くものを選んでください。

入出力例

入力 1

4 16

出力 1

3 1 2 4

注記

例えば $3,2,1,4$ など、ほかの数列も可能ですが、$3,1,2,4$ が辞書順で最小です。

問題作成:Harry Wiggins(2002)。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.