# Lagrange four-square (Bachet Conjecture) for 37

<-- Enter Number

What is the Lagrange four-square (Bachet Conjecture) for 37

Lagrange's Four Square Theorem states that any natural number (p) can be stated as the sum of four-square integers
p = a2 + b2 + c2 + d2

## Step 1: - Determine a:

Step 1a: Floor(√37 = 6.0827625302982) = Floor(6.0827625302982)
Step 1a: Floor(6.0827625302982) = 6 <-- This is the maximum value of a, call it max_a

Step 1b. Obtain the first value of a such that a2 ≥ n/4, call it min_a
Start with min_a = 1 and increase by 1 until we reach or breach n/4 → 37/4 = 9.25
When min_a = 4, then it is a2 = 16 ≥ 9.25, so min_a = 4

## a = 4

Step 3a: Determine max_b which is Floor(√n - a2)
max_b = Floor(√37 - 42)
max_b = Floor(√37 - 16)
max_b = Floor(√21)
max_b = Floor(4.5825756949558)
max_b = 4

Step 3b. Obtain the first value of b such that b2 ≥ (n - a2)/3, call it min_b
Start with min_b = 1 and increase by 1until we reach or breach (n - a2)/3 → (37 - 42)/3 = 7
When min_b = 3, then it is b2 = 9 ≥ 7, so min_b = 3

## b = 3

Step 5a: Determine max_c which is Floor(√n - a2 - b2)
max_c = Floor(√37 - 42 - 32)
max_c = Floor(√37 - 16 - 9)
max_c = Floor(√12)
max_c = Floor(3.4641016151378)
max_c = 3

Step 5b. Obtain the first value of b such that b2 ≥ (n - a2)/3, call it min_b
Start with min_c = 1 and increase by 1 until we reach or breach (n - a2 - b2 )/2 → (37 - 42 - 32)/2 = 6
When min_c = 3, then it is c2 = 9 ≥ 6, so min_c = 3

## c = 3

Step 7: Determine if d is an integer solution which is √n - a2 - b2
max_d = √37 - 42 - 32 - 32
max_d = √37 - 16 - 9 - 9
max_d = √3
max_d = 1.7320508075689

Since max_d = 1.7320508075689 is not an integer, this is not a solution

## b = 4

Step 5a: Determine max_c which is Floor(√n - a2 - b2)
max_c = Floor(√37 - 42 - 42)
max_c = Floor(√37 - 16 - 16)
max_c = Floor(√5)
max_c = Floor(2.2360679774998)
max_c = 2

Step 5b. Obtain the first value of b such that b2 ≥ (n - a2)/3, call it min_b
Start with min_c = 1 and increase by 1 until we reach or breach (n - a2 - b2 )/2 → (37 - 42 - 42)/2 = 2.5
When min_c = 2, then it is c2 = 4 ≥ 2.5, so min_c = 2

## c = 2

Step 7: Determine if d is an integer solution which is √n - a2 - b2
max_d = √37 - 42 - 42 - 22
max_d = √37 - 16 - 16 - 4
max_d = √1
max_d = 1

Since max_d = 1, then (a, b, c, d) = (4, 4, 2, 1) is an integer solution proven below
42 + 42 + 22 + 12 → 16 + 16 + 4 + 1 = 37

## a = 5

Step 3a: Determine max_b which is Floor(√n - a2)
max_b = Floor(√37 - 52)
max_b = Floor(√37 - 25)
max_b = Floor(√12)
max_b = Floor(3.4641016151378)
max_b = 3

Step 3b. Obtain the first value of b such that b2 ≥ (n - a2)/3, call it min_b
Start with min_b = 1 and increase by 1until we reach or breach (n - a2)/3 → (37 - 52)/3 = 4
When min_b = 2, then it is b2 = 4 ≥ 4, so min_b = 2

## b = 2

Step 5a: Determine max_c which is Floor(√n - a2 - b2)
max_c = Floor(√37 - 52 - 22)
max_c = Floor(√37 - 25 - 4)
max_c = Floor(√8)
max_c = Floor(2.8284271247462)
max_c = 2

Step 5b. Obtain the first value of b such that b2 ≥ (n - a2)/3, call it min_b
Start with min_c = 1 and increase by 1 until we reach or breach (n - a2 - b2 )/2 → (37 - 52 - 22)/2 = 4
When min_c = 2, then it is c2 = 4 ≥ 4, so min_c = 2

## c = 2

Step 7: Determine if d is an integer solution which is √n - a2 - b2
max_d = √37 - 52 - 22 - 22
max_d = √37 - 25 - 4 - 4
max_d = √4
max_d = 2

Since max_d = 2, then (a, b, c, d) = (5, 2, 2, 2) is an integer solution proven below
52 + 22 + 22 + 22 → 25 + 4 + 4 + 4 = 37

## b = 3

Step 5a: Determine max_c which is Floor(√n - a2 - b2)
max_c = Floor(√37 - 52 - 32)
max_c = Floor(√37 - 25 - 9)
max_c = Floor(√3)
max_c = Floor(1.7320508075689)
max_c = 1

Step 5b. Obtain the first value of b such that b2 ≥ (n - a2)/3, call it min_b
Start with min_c = 1 and increase by 1 until we reach or breach (n - a2 - b2 )/2 → (37 - 52 - 32)/2 = 1.5
When min_c = 2, then it is c2 = 4 ≥ 1.5, so min_c = 2

## a = 6

Step 3a: Determine max_b which is Floor(√n - a2)
max_b = Floor(√37 - 62)
max_b = Floor(√37 - 36)
max_b = Floor(√1)
max_b = Floor(1)
max_b = 1

Step 3b. Obtain the first value of b such that b2 ≥ (n - a2)/3, call it min_b
Start with min_b = 1 and increase by 1until we reach or breach (n - a2)/3 → (37 - 62)/3 = 0.33333333333333
When min_b = 1, then it is b2 = 1 ≥ 0.33333333333333, so min_b = 1

## b = 1

Step 5a: Determine max_c which is Floor(√n - a2 - b2)
max_c = Floor(√37 - 62 - 12)
max_c = Floor(√37 - 36 - 1)
max_c = Floor(√0)
max_c = Floor(0)
max_c = 0

Step 5b. Obtain the first value of b such that b2 ≥ (n - a2)/3, call it min_b
Start with min_c = 1 and increase by 1 until we reach or breach (n - a2 - b2 )/2 → (37 - 62 - 12)/2 = 0
When min_c = 1, then it is c2 = 1 ≥ 0, so min_c = 1

## List out 2 solutions:

(a, b, c, d) = (4, 4, 2, 1)
(a, b, c, d) = (5, 2, 2, 2)

Special thanks to Stack Overflow for this algorithm suggestion