from math import isqrt
def four_squares_count(n):
"""Compte r_4(n) = 8 * sum_{d | n, 4 not | d} d."""
if n == 0:
return 1
total = 0
d = 1
while d * d <= n:
if n % d == 0:
for dd in {d, n // d}:
if dd % 4 != 0:
total += dd
d += 1
return 8 * total
print('Verification de la formule de Jacobi pour r_4(n) sur n <= 30')
print()
print(f"{'n':>4} | {'r_4(n) (Jacobi)':>15} | {'decomposition directe'}")
print('-' * 60)
for n in range(1, 31):
r = four_squares_count(n)
# Decomposition directe pour n <= 30
decomps = []
for a in range(0, isqrt(n) + 1):
for b in range(a, isqrt(n - a * a) + 1):
for c in range(b, isqrt(n - a * a - b * b) + 1):
d2 = n - a * a - b * b - c * c
if d2 < c * c:
break
d = isqrt(d2)
if d * d == d2 and d >= c:
decomps.append((a, b, c, d))
break
if decomps and decomps[-1]:
break
if decomps and decomps[-1]:
break
dec_str = str(decomps[0]) if decomps else 'N/A'
print(f'{n:>4} | {r:>15} | {dec_str}')Verification de la formule de Jacobi pour r_4(n) sur n <= 30
n | r_4(n) (Jacobi) | decomposition directe
------------------------------------------------------------
1 | 8 | (0, 0, 0, 1)
2 | 24 | (0, 0, 1, 1)
3 | 32 | (0, 1, 1, 1)
4 | 24 | (0, 0, 0, 2)
5 | 48 | (0, 0, 1, 2)
6 | 96 | (0, 1, 1, 2)
7 | 64 | (1, 1, 1, 2)
8 | 24 | (0, 0, 2, 2)
9 | 104 | (0, 0, 0, 3)
10 | 144 | (0, 0, 1, 3)
11 | 96 | (0, 1, 1, 3)
12 | 96 | (0, 2, 2, 2)
13 | 112 | (0, 0, 2, 3)
14 | 192 | (0, 1, 2, 3)
15 | 192 | (1, 1, 2, 3)
16 | 24 | (0, 0, 0, 4)
17 | 144 | (0, 0, 1, 4)
18 | 312 | (0, 0, 3, 3)
19 | 160 | (0, 1, 3, 3)
20 | 144 | (0, 0, 2, 4)
21 | 256 | (0, 1, 2, 4)
22 | 288 | (0, 2, 3, 3)
23 | 192 | (1, 2, 3, 3)
24 | 96 | (0, 2, 2, 4)
25 | 248 | (0, 0, 0, 5)
26 | 336 | (0, 0, 1, 5)
27 | 320 | (0, 1, 1, 5)
28 | 192 | (1, 1, 1, 5)
29 | 240 | (0, 0, 2, 5)
30 | 576 | (0, 1, 2, 5)