Connection Status:
Competition Arena > FourSquareSum
SRM 764 · 2019-08-09 · by adamant · Math, Simple Math
Class Name: FourSquareSum
Return Type: int[]
Method Name: DivideByTwo
Arg Types: (int, int, int, int)
Problem Statement

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}.

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
0)
1
2
3
4
Returns: {1, 1, 2, 3 }

12+22+32+42=30, so 12+12+22+32=15 will do.

1)
5
7
1
3
Returns: {1, 1, 2, 6 }

52+72+12+32=84, so 12+12+22+62=42 will do.

2)
0
0
0
0
Returns: {0, 0, 0, 0 }
3)
0
1234
0
1000000
Returns: {617, 617, 500000, 500000 }
4)
1000000
0
0
1000000
Returns: {500000, 500000, 500000, 500000 }

Submissions are judged against all 22 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class FourSquareSum with a public method vector<int> DivideByTwo(int a, int b, int c, int d) · 22 test cases · 2 s / 256 MB per case

Submitting as anonymous