QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 2048 MB 満点: 100

#7704. 加减四个平方数

統計

每一个非负整数 $n$ 都可以写成四个整数的平方和: $$n = a^2 + b^2 + c^2 + d^2$$ 通过允许减法,可以将 $n$ 写成更多种形式;事实上,有无穷多种写法。 在本题中,你需要计算将输入 $n$ 表示为四个平方数的和或差的不同方式的数量,并满足以下限制:

首先,我们需要定义什么是“不同”。 $a, b, c, d$ 中的任何一个都可以被替换为它的相反数。我们不希望将这些视为不同,因此我们只统计不同的平方值。 重排 $a, b, c, d$ 不会产生不同的表示。 因此,我们将非负整数 $n$ 的“加减四平方表示”定义为一个由四个完全平方数组成的序列,按非递增顺序排列,并带有加号或减号,其计算结果为 $n$。

此外,我们增加以下限制: 第一个平方数必须不超过 $n$,以避免产生无穷多种表示。 如果同一个平方数出现多次,则所有出现的位置必须都带有(可能是隐含的)加号,或者所有出现的位置都带有减号。这避免了类似以下的情况: $64 + 36 - 36 + 0$ * 零的平方必须带有加号。

例如,加起来等于 64 的唯一平方和形式是: $64 + 0 + 0 + 0$ $16 + 16 + 16 + 16$

如果我们允许使用减号并遵守上述附加限制,则以下每种形式的和均为 64: $64 + 25 - 16 - 9$ $64 - 25 + 16 + 9$ $64 + 0 + 0 + 0$ $49 + 49 - 25 - 9$ $49 + 36 - 25 + 4$ $49 + 25 - 9 - 1$ $49 + 16 - 1 + 0$ $36 + 36 - 9 + 1$ $36 + 36 - 4 - 4$ $36 + 25 + 4 - 1$ $36 + 16 + 16 - 4$ $16 + 16 + 16 + 16$

编写一个程序,输入一个非负整数 $n$,输出 $n$ 的不同加减四平方表示的数量。

输入格式

输入包含一行,为一个非负十进制整数 ($0 < n \le 5000$)。

输出格式

输出一行,包含一个十进制整数,表示 $n$ 的不同加减四平方表示的数量。

样例

样例输入 1

64

样例输出 1

12

样例输入 2

65

样例输出 2

10

样例输入 3

2023

样例输出 3

245

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.