QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 2048 MB مجموع النقاط: 100

#16830. 完全平方数

الإحصائيات

数论中一个著名的定理指出,每个正整数都可以表示为四个完全平方数之和。然而,你注意到通常更少的平方数就足够了。例如,27 只需要三个完全平方数:$27 = 5^2 + 1^2 + 1^2$。

你与一位数学家朋友分享了你的观察,他脱口而出以下关于完全平方数的结论:

  • 奇素数 $p$ 可以表示为两个平方数之和,当且仅当 $p \equiv 1 \pmod 4$。
  • 如果两个正整数 $a$ 和 $b$ 都可以表示为两个平方数之和,那么它们的乘积 $ab$ 也可以。
  • 每个正整数都可以表示为三个完全平方数之和,除非它具有 $4^a \cdot (8b + 7)$ 的形式,其中 $a$ 和 $b$ 是某些非负整数。

这最后一个关于三个平方数之和的结论引起了你的兴趣,因此你想编写一个程序,通过输出具体的平方数来验证这一结论是否正确。

输入格式

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

输出格式

如果 $n$ 可以表示为三个平方数之和,输出三个整数 $x$、$y$ 和 $z$。如果 $0 \le x, y, z \le \sqrt{n}$ 且 $n = x^2 + y^2 + z^2$,则你的答案将被判定为正确。如果 $x$、$y$ 和 $z$ 有多种合法选择,你可以输出其中任意一种。即使 $n$ 可以表示为两个或更少平方数之和,你也必须输出恰好三个整数。

如果 $n$ 不能表示为三个平方数之和,输出 -1,且不输出其他内容。

样例

输入样例 1

22

输出样例 1

3 3 2

输入样例 2

23

输出样例 2

-1

输入样例 3

999999999989

输出样例 3

471545 0 881842

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.