TopcoderArchive
SRM9 Aug 2019
SRM 764

FourSquareSum

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given four non-negative integers a, b, c, d, and are given that 2n = a2 + b2 + c2 + d2.

You have to find four non-negative integers s, x, y, z such that n = s2 + x2 + y2 + z2.

(It may be proven that such a quadruple always exists.)

Return a int[] containing the values {s, x, y, z}.

Definition

Class:
FourSquareSum
Method:
DivideByTwo
Parameters:
int, int, int, int
Returns:
int[]
Method signature:
int[] DivideByTwo(int a, int b, int c, int d)
(be sure your method is public)

Notes

  • The order of the four elements in your return does not matter.

Constraints

  • 0 ≤ a,b,c,d ≤ 106,
  • a2+b2+c2+d2 is even.

Examples

  1. 1
    2
    3
    4
    Returns: {1, 1, 2, 3 }
    12+22+32+42=30, so 12+12+22+32=15 will do.
  2. 5
    7
    1
    3
    Returns: {1, 1, 2, 6 }
    52+72+12+32=84, so 12+12+22+62=42 will do.
  3. 0
    0
    0
    0
    Returns: {0, 0, 0, 0 }
Back to all problems