# Python program for OEIS A368207 # being a translation of the CWEB program by Don Knuth # Michael S. Branicky, Dec 19 2023 maxn = 10001 th = [0 for _ in range(maxn)] xs = [0 for _ in range(maxn)] sum = 0 bfile = open("b368207.txt", "w") def th_and_xs(): global th, xs m = 1 nn = 3 for n in range(1, maxn): d = m while n%d: d -= 1 th[n] = d k = 0 for d in range(m, 0, -1): if not n%d: k += d+d-1 if d*d==n else d+d+d+d-2 xs[n]=k; if n == nn: m += 1 nn += m+m+1 def b(n): global th, xs, sum sum = 0 k, kk = 1, n-1 while k < kk: d, dd = k//th[k], th[kk] if d < dd: for i in range(d, dd): if not k%i: for j in range(dd, i, -1): if not kk%j: solution(k//i, i, j, kk//j) k += 1 kk -= 1 bfile.write(f"{n} {sum+xs[n]}\n") def solution(a, b, c, d): global sum if a == b: if c == d: sum += 1 else: sum += 2 elif c==d: sum += 2 else: sum += 4 bfile.write("# computed by a Python translation of Don Knuth's CWEB program on 19 December 2023\n"); th_and_xs() for n in range(1, maxn): b(n) bfile.write("\n") bfile.close()