Logo
(追記) (追記ここまで)

32850번 - Perfect Squares 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB189463628.346%

문제

A famous theorem in number theory states that every positive integer can be written as the sum of four perfect squares. You have noticed, though, that usually fewer squares are enough. For example, 27ドル$ only requires three perfect squares: 27ドル = 5^2 + 1^2 + 1^2$.

You share your observations with a mathematician friend, who rattles off the following perfect squares facts:

  • An odd prime $p$ can be written as the sum of two squares if and only if $p \equiv 1 \pmod 4$.
  • If two positive integers $a$ and $b$ can be written as the sum of two squares, then so can their product $ab$.
  • Every positive integer can be written as the sum of three perfect squares, unless it is of the form 4ドル^a \cdot (8b + 7),ドル where $a$ and $b$ are some non-negative integers.

This last fact about sums of three squares intrigues you, and so you would like to write a program that verifies the claim is true by producing the actual squares.

입력

Input contains a single integer $n$ (1ドル ≤ n ≤ 10^{12}$).

출력

If $n$ can be expressed as the sum of three squares, output three integers $x,ドル $y,ドル and $z$. Your answer will be judged correct if 0ドル ≤ x, y, z ≤ \sqrt{n}$ and $n = x^2 +y^2 +z^2$. If there are multiple valid choices for $x,ドル $y,ドル and $z$ you may output any of them. You must output exactly three integers, even if $n$ can be expressed as the sum of two or fewer squares.

If $n$ cannot be expressed as the sum of three squares, output $-1$ and no further output.

제한

예제 입력 1

22

예제 출력 1

3 3 2

예제 입력 2

23

예제 출력 2

-1

예제 입력 3

999999999989

예제 출력 3

471545 0 881842

힌트

출처

ICPC > Regionals > North America > Southeast USA Regional > 2024 Southeast USA Regional Programming Contest > Division 1 J번

ICPC > Regionals > North America > Southeast USA Regional > 2024 Southeast USA Regional Programming Contest > Division 2 J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /