QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100

#11148. 背包

统计

Bajtazar 是一位多才多艺的专家,但他对自己的收入并不满意。在朋友的建议下,他决定投资一些基金。

目前有五家公司可供选择:Bitoff Securities LLC、Bajtton Unmount、Bajtou Hedge Fund Group、BajtConneeeeeeeeeect 和 Bajtocka Kasa Oszczędności。每家公司都为投资者提供相同的方案:你支付一笔小额入场费,然后立即开始赚钱!在第 $i$ 天,你的虚拟账户中会增加 $i$ 个 Bajtolar。你可以随时结束投资并提取迄今为止积累的金额,即如果你在 $k$ 天后选择退出,总金额为 $1 + 2 + \dots + k = \frac{k(k+1)}{2}$。

这种系统可以带来巨大的收益,但 Bajtazar 并不是一个贪婪的人。他只需要一笔总额恰好为 $n$ 个 Bajtolar 的资金(更高的收益会被征收高额税款)。请帮助他投资于这五家公司中的一部分(或全部),使得所有投资的提取金额之和恰好等于 $n$。

输出所选公司的数量(1 到 5 之间)以及 Bajtazar 从每家公司投资中获得的金额。每个金额必须是形如 $\frac{k(k+1)}{2}$ 的形式,其中 $k$ 为某个正整数。(这种形式的数字有时被称为“金字塔数”。)

可以证明,对于题目给定范围内的每一个 $n$,这都是可行的。

输入格式

输入仅包含一行,包含一个整数 $n$ ($1 \le n \le 10^{18}$)。

输出格式

第一行输出一个整数 $s$ ($1 \le s \le 5$),表示 Bajtazar 应该投资的公司数量。

第二行输出 $s$ 个正整数,表示从每家选定公司获得的金额。这些数字之和必须恰好等于 $n$。

如果存在多种可能的解,输出其中任意一个即可。

样例

输入 1

18

输出 1

4
6 1 10 1

说明 1

Bajtazar 可以选择投资四家公司。如果他分别在第 1 天、第 1 天、第 3 天和第 4 天结束投资,他将获得的总金额为: $(1) + (1) + (1 + 2 + 3) + (1 + 2 + 3 + 4) = 1 + 1 + 6 + 10 = 18$

因此,我们可以输出数字 1, 1, 6, 10。输出数字的顺序无关紧要,因此 6, 1, 10, 1 也是一个正确的解。

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.