# Check it yourself: Erdos problems 64 and 647

Don't take our word for it. Each result here comes with its files and a check guide, and each guide says which checks you can rerun yourself. Some results rest on logs from programs that are not part of this book, or on files available on request; the guide says which. Where your run matches ours, you checked that part rather than trusted it. If something breaks, confuses you or does not match, you are welcome to tell us. We fix mistakes in the open and credit the person who found them. Why a recipe and not our program: https://gocheckyourself.org/how-to-check/

You do not have to trust our results or our programs. This page tells you, step by step, how to check the published files with tools you already have. The full written recipe is the last chapter of https://gocheckyourself.org/text/erdos-problems-experts.txt (heading 'Verify: Erdos problems 64 and 647').

Steps 1 to 9, 12 have the command for Windows PowerShell and for macOS or Linux (bash), the output you should see, and a plain sentence on what a match means and what it does not. Steps 10 to 11 have no copy-paste script yet: each names the recipe to write yourself and the output to expect. If your output is different, the step has failed; do not skip it.

You need: a command line, and Python 3.8 or later (python on Windows, python3 on macOS or Linux) for the steps that run a script. Windows PowerShell 5.1 or later (pwsh also works). Scripts are short; read them before you run them.

## What is known not to work today

- Problem 64, small orders 4 to 15: needs a graph enumerator such as nauty geng (free, not ours). Orders to 15 take about 30 to 50 seconds in the book's own timing; order 16 adds minutes.
- Problem 647 part 3 (the scan from 6,350,464 to 10^9): the script is in Step 9 below. In our own re-run it took about 5 seconds.
- Problem 647 above 10^9: the sieve itself is not shipped. Part 4 checks the bookkeeping of its logs, not the sieve.

## Step 1: Make an empty working folder and say where the files are.

Windows PowerShell:

```powershell
$ProgressPreference = "SilentlyContinue"
$BASE = "https://gocheckyourself.org/data/files/erdos-problems"
New-Item -ItemType Directory -Force check-erdos-problems | Out-Null
Set-Location check-erdos-problems
```

macOS or Linux (bash):

```bash
BASE="https://gocheckyourself.org/data/files/erdos-problems"
mkdir -p check-erdos-problems && cd check-erdos-problems
```

You should see:

```
No output.
```

What a match shows, and what it does not: Nothing; this just makes a folder.

Cost: instant.

## Step 2: Download the list of fingerprints (SHA-256) that the book publishes for its files.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/erdos-problems/certificates/SHA256SUMS.txt  2b18d22e74a3722a1f77bc8f1c6e83415cd5158a47deb1bd3e50252d3c10b113

Windows PowerShell:

```powershell
New-Item -ItemType Directory -Force certificates | Out-Null
Invoke-WebRequest -UseBasicParsing -UserAgent "Mozilla/5.0" "$BASE/certificates/SHA256SUMS.txt" -OutFile certificates/SHA256SUMS.txt
Set-Location certificates
```

macOS or Linux (bash):

```bash
mkdir -p certificates
curl -fsSL "$BASE/certificates/SHA256SUMS.txt" -o certificates/SHA256SUMS.txt
cd certificates
```

You should see:

```
No output. The file certificates/SHA256SUMS.txt exists. Each line is 64 hex digits, a space, an optional star, and a file path.
```

What a match shows, and what it does not: The list comes from the same site as the files, so by itself it just catches damaged or swapped files, not a site that lies in both places. Compare the list's own SHA-256 (see inputs) with a copy you trust, such as one a friend keeps, or one kept anywhere other than this site.

Cost: instant.

## Step 3: Download every file named in the list, keeping the folder layout the list expects.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/erdos-problems/certificates/SHA256SUMS.txt  2b18d22e74a3722a1f77bc8f1c6e83415cd5158a47deb1bd3e50252d3c10b113

Windows PowerShell:

```powershell
Get-Content SHA256SUMS.txt | Where-Object { $_.Trim() } | ForEach-Object {
  $rel = ($_ -replace '^[0-9a-fA-F]{64} [ *]','') -replace '^\./',''
  New-Item -ItemType Directory -Force (Split-Path -Parent (Join-Path $PWD $rel)) | Out-Null
  try { Invoke-WebRequest -UseBasicParsing -UserAgent "Mozilla/5.0" "$BASE/certificates/$rel" -OutFile $rel } catch { "NOT FOUND: $rel" }
}
```

macOS or Linux (bash):

```bash
while read -r h p; do
  p="${p#\*}"; p="${p#./}"; [ -z "$p" ] && continue
  mkdir -p "$(dirname "$p")"
  curl -fsSL "$BASE/certificates/$p" -o "$p" || echo "NOT FOUND: $p"
done < SHA256SUMS.txt
```

You should see:

```
One file per list line (19 lines). No output means every download worked.
```

What a match shows, and what it does not: A missing file can come back as the site's home page (status 200) instead of a not-found. The next step catches that, because the page's hash will not match.

Cost: seconds to a minute.

## Step 4: Compare the SHA-256 fingerprint of every downloaded file with the published list.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/erdos-problems/certificates/SHA256SUMS.txt  2b18d22e74a3722a1f77bc8f1c6e83415cd5158a47deb1bd3e50252d3c10b113

Windows PowerShell:

```powershell
$ok = 0; $bad = 0
Get-Content SHA256SUMS.txt | Where-Object { $_.Trim() } | ForEach-Object {
  $h = $_.Substring(0,64).ToLower()
  $rel = ($_ -replace '^[0-9a-fA-F]{64} [ *]','') -replace '^\./',''
  $f = Get-FileHash -Algorithm SHA256 -LiteralPath $rel -ErrorAction SilentlyContinue
  if ($f -and $f.Hash.ToLower() -eq $h) { $ok++ } else { $bad++; "NOT OK: $rel" }
}
"$ok OK, $bad not OK"
```

macOS or Linux (bash):

```bash
# Linux: sha256sum.  macOS: use "shasum -a 256 -c" instead of "sha256sum -c".
if command -v sha256sum >/dev/null; then C="sha256sum -c"; else C="shasum -a 256 -c"; fi
$C SHA256SUMS.txt 2>&1 | grep -v ": OK$" ; echo "$($C SHA256SUMS.txt 2>/dev/null | grep -c ": OK$") OK"
```

You should see:

```
PowerShell prints a line "19 OK, 0 not OK". bash prints every line that is not OK, then "19 OK".
```

What a match shows, and what it does not: A match shows that your files are exactly the files the list names. What the files say is tested by the other steps of this recipe. 

Cost: seconds.

## Step 5: Problem 64: check the four 24-vertex graphs (3-regular, no 4-cycle, no 8-cycle, a 16-cycle).

Files used (SHA-256):
- https://gocheckyourself.org/data/files/erdos-problems/certificates/erdos64/cubic24.g6  ce744beeed503233766e67d798bfd28ad4bb44e05e5c16d190c83a712bbd046b

Windows PowerShell:

```powershell
@'
# Problem 64: the four 24-vertex graphs.  Usage: python erdos64_anchor_graphs.py erdos64/cubic24.g6
import sys
def decode(s):
    n = ord(s[0]) - 63
    bits = [((ord(c) - 63) >> sh) & 1 for c in s[1:] for sh in range(5, -1, -1)]
    adj = [set() for _ in range(n)]
    k = 0
    for j in range(1, n):
        for i in range(j):
            if bits[k]:
                adj[i].add(j); adj[j].add(i)
            k += 1
    return adj

def has_cycle(adj, L):
    for s in range(len(adj)):
        def dfs(v, depth, seen):
            if depth == L:
                return s in adj[v]
            for w in adj[v]:
                if w > s and w not in seen:
                    seen.add(w)
                    if dfs(w, depth + 1, seen):
                        return True
                    seen.discard(w)
            return False
        if dfs(s, 1, {s}):
            return True
    return False

for line in open(sys.argv[1]).read().split():
    adj = decode(line)
    print(len(adj), "vertices; 3-regular:", all(len(a) == 3 for a in adj),
          "; 4-cycle:", has_cycle(adj, 4), "; 8-cycle:", has_cycle(adj, 8), "; 16-cycle:", has_cycle(adj, 16))
'@ | Set-Content -Encoding utf8 erdos64_anchor_graphs.py
python erdos64_anchor_graphs.py erdos64/cubic24.g6
```

macOS or Linux (bash):

```bash
cat > erdos64_anchor_graphs.py <<'EOF'
# Problem 64: the four 24-vertex graphs.  Usage: python erdos64_anchor_graphs.py erdos64/cubic24.g6
import sys
def decode(s):
    n = ord(s[0]) - 63
    bits = [((ord(c) - 63) >> sh) & 1 for c in s[1:] for sh in range(5, -1, -1)]
    adj = [set() for _ in range(n)]
    k = 0
    for j in range(1, n):
        for i in range(j):
            if bits[k]:
                adj[i].add(j); adj[j].add(i)
            k += 1
    return adj

def has_cycle(adj, L):
    for s in range(len(adj)):
        def dfs(v, depth, seen):
            if depth == L:
                return s in adj[v]
            for w in adj[v]:
                if w > s and w not in seen:
                    seen.add(w)
                    if dfs(w, depth + 1, seen):
                        return True
                    seen.discard(w)
            return False
        if dfs(s, 1, {s}):
            return True
    return False

for line in open(sys.argv[1]).read().split():
    adj = decode(line)
    print(len(adj), "vertices; 3-regular:", all(len(a) == 3 for a in adj),
          "; 4-cycle:", has_cycle(adj, 4), "; 8-cycle:", has_cycle(adj, 8), "; 16-cycle:", has_cycle(adj, 16))
EOF
python3 erdos64_anchor_graphs.py erdos64/cubic24.g6
```

You should see:

```
Four lines, each: '24 vertices; 3-regular: True ; 4-cycle: False ; 8-cycle: False ; 16-cycle: True'.
```

What a match shows, and what it does not: It does not show anything about graphs on 23 or fewer vertices, nor that there are no other such graphs.

Cost: a few seconds.

## Step 6: Problem 647 part 1: recompute the residue classes and compare them with classes_d0.txt.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/erdos-problems/certificates/erdos647/classes_d0.txt  86941dca4571c797c958b7f268449c49d1677ea41290482c53b4203bc6b7f5eb

Windows PowerShell:

```powershell
@'
# Problem 647, part 1: the residue classes. Usage: python erdos647_part1_classes.py erdos647/classes_d0.txt
import sys
M = 2**6 * 3**4 * 5**2 * 7**2          # 6,350,400
PP = [(2, 6, 64), (3, 4, 81), (5, 2, 25), (7, 2, 49)]   # prime, exponent a, prime power q

def vp(x, p):
    e = 0
    while x % p == 0:
        x //= p; e += 1
    return e

# for each prime power and each residue x: for k = 1..64 the pair (exponent+1, t != 0)
tab = []
for p, a, q in PP:
    rows = []
    for x in range(q):
        row = []
        for k in range(1, 65):
            t = (x - k) % q
            row.append((a + 1, 0) if t == 0 else (vp(t, p) + 1, 1))
        rows.append(row)
    tab.append(rows)

found = []
def rec(level, prod, allnz, xs):
    if level == 4:
        if all(prod[i] * (2 if allnz[i] else 1) <= i + 3 for i in range(64)):   # b <= k + 2
            found.append(tuple(xs))
        return
    for x in range(PP[level][2]):
        row = tab[level][x]
        np_ = [prod[i] * row[i][0] for i in range(64)]
        if any(np_[i] > i + 3 for i in range(64)):      # b never shrinks, so prune
            continue
        rec(level + 1, np_, [allnz[i] and row[i][1] for i in range(64)], xs + [x])
rec(0, [1] * 64, [1] * 64, [])

classes = sorted(sum(x * (M // q) * pow(M // q, -1, q) for (p, a, q), x in zip(PP, xs)) % M for xs in found)
shipped = [int(s) for s in open(sys.argv[1]).read().split()]
print("survivors:", len(classes))
print("all multiples of 2520:", all(c % 2520 == 0 for c in classes))
print("equal to shipped file:", classes == shipped)
'@ | Set-Content -Encoding utf8 erdos647_part1_classes.py
python erdos647_part1_classes.py erdos647/classes_d0.txt
```

macOS or Linux (bash):

```bash
cat > erdos647_part1_classes.py <<'EOF'
# Problem 647, part 1: the residue classes. Usage: python erdos647_part1_classes.py erdos647/classes_d0.txt
import sys
M = 2**6 * 3**4 * 5**2 * 7**2          # 6,350,400
PP = [(2, 6, 64), (3, 4, 81), (5, 2, 25), (7, 2, 49)]   # prime, exponent a, prime power q

def vp(x, p):
    e = 0
    while x % p == 0:
        x //= p; e += 1
    return e

# for each prime power and each residue x: for k = 1..64 the pair (exponent+1, t != 0)
tab = []
for p, a, q in PP:
    rows = []
    for x in range(q):
        row = []
        for k in range(1, 65):
            t = (x - k) % q
            row.append((a + 1, 0) if t == 0 else (vp(t, p) + 1, 1))
        rows.append(row)
    tab.append(rows)

found = []
def rec(level, prod, allnz, xs):
    if level == 4:
        if all(prod[i] * (2 if allnz[i] else 1) <= i + 3 for i in range(64)):   # b <= k + 2
            found.append(tuple(xs))
        return
    for x in range(PP[level][2]):
        row = tab[level][x]
        np_ = [prod[i] * row[i][0] for i in range(64)]
        if any(np_[i] > i + 3 for i in range(64)):      # b never shrinks, so prune
            continue
        rec(level + 1, np_, [allnz[i] and row[i][1] for i in range(64)], xs + [x])
rec(0, [1] * 64, [1] * 64, [])

classes = sorted(sum(x * (M // q) * pow(M // q, -1, q) for (p, a, q), x in zip(PP, xs)) % M for xs in found)
shipped = [int(s) for s in open(sys.argv[1]).read().split()]
print("survivors:", len(classes))
print("all multiples of 2520:", all(c % 2520 == 0 for c in classes))
print("equal to shipped file:", classes == shipped)
EOF
python3 erdos647_part1_classes.py erdos647/classes_d0.txt
```

You should see:

```
survivors: 2205
all multiples of 2520: True
equal to shipped file: True
```

What a match shows, and what it does not: It depends on the residue lemma, whose proof is in the chapter. It does not show the claim above 10^9 by itself.

Cost: about 5 to 30 seconds.

## Step 7: Problem 647 part 2: brute force for n up to 6,350,464.

Windows PowerShell:

```powershell
@'
# Problem 647, part 2: brute force to 6,350,464.  Usage: python erdos647_part2_bruteforce.py
N = 6350464
spf = list(range(N + 1))
i = 2
while i * i <= N:
    if spf[i] == i:
        for j in range(i * i, N + 1, i):
            if spf[j] == j:
                spf[j] = i
    i += 1
tau = [0] * (N + 1)
tau[1] = 1
for m in range(2, N + 1):
    p = spf[m]; r = m // p; e = 1
    while r % p == 0:
        r //= p; e += 1
    tau[m] = tau[r] * (e + 1)
sols, mx = [], 0                      # the maximum over no numbers is 0
for n in range(1, N + 1):
    if mx <= n + 2:
        sols.append(n)
    mx = max(mx, n + tau[n])
print("solutions:", sols)
'@ | Set-Content -Encoding utf8 erdos647_part2_bruteforce.py
python erdos647_part2_bruteforce.py
```

macOS or Linux (bash):

```bash
cat > erdos647_part2_bruteforce.py <<'EOF'
# Problem 647, part 2: brute force to 6,350,464.  Usage: python erdos647_part2_bruteforce.py
N = 6350464
spf = list(range(N + 1))
i = 2
while i * i <= N:
    if spf[i] == i:
        for j in range(i * i, N + 1, i):
            if spf[j] == j:
                spf[j] = i
    i += 1
tau = [0] * (N + 1)
tau[1] = 1
for m in range(2, N + 1):
    p = spf[m]; r = m // p; e = 1
    while r % p == 0:
        r //= p; e += 1
    tau[m] = tau[r] * (e + 1)
sols, mx = [], 0                      # the maximum over no numbers is 0
for n in range(1, N + 1):
    if mx <= n + 2:
        sols.append(n)
    mx = max(mx, n + tau[n])
print("solutions:", sols)
EOF
python3 erdos647_part2_bruteforce.py
```

You should see:

```
solutions: [1, 2, 3, 4, 5, 6, 8, 10, 12, 24]
```

What a match shows, and what it does not: It shows the claim just up to 6,350,464 (part 3 of the chapter carries it to 10^9).

Cost: about 10 to 60 seconds, about 1 GB of memory in plain Python lists.

## Step 8: Problem 647 part 4: the bookkeeping of the sieve logs from 10^8 to 10^14.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/erdos-problems/certificates/erdos647/prod_1e8_1e10.txt  5ede4baaf2aed587c08998855eff71e714c6cef45bd1b523d61d0e24970d7cb0

Windows PowerShell:

```powershell
@'
# Problem 647, part 4: the sieve-log bookkeeping.  Usage: python erdos647_part4_logs.py erdos647
import os, sys
M = 6350400
d = sys.argv[1]
classes = [int(s) for s in open(os.path.join(d, "classes_d0.txt")).read().split()]
chunks = {}
for fn in sorted(os.listdir(d)):
    if not fn.startswith("prod_"):
        continue
    hdr, done, bad = None, False, False
    for line in open(os.path.join(d, fn)):
        if line.startswith("# sieve647"):
            hdr = dict(kv.split("=", 1) for kv in line.split()[2:])
        elif line.startswith("# DONE"):
            done = True
        elif line.startswith("S"):
            bad = True
        elif line.startswith("C "):
            f = line.split()
            r, c, s1, s2 = int(f[1]), int(f[3]), int(f[5]), int(f[7])
            ch = chunks.setdefault((int(hdr["nlo"]), int(hdr["nhi"])), {"cls": {}, "surv": 0})
            ch["cls"].setdefault(r, []).append(c)
            ch["surv"] += s1 + s2
    assert hdr and done and not bad, fn
keys = sorted(chunks)
print("chunks:", keys)
print("contiguous from 10^8+1 to 10^14:", keys[0][0] == 10**8 + 1 and keys[-1][1] == 10**14 and all(a[1] + 1 == b[0] for a, b in zip(keys, keys[1:])))
tot = []
for lo, hi in keys:
    ch = chunks[(lo, hi)]
    assert set(ch["cls"]) == set(classes) and all(len(v) == 1 for v in ch["cls"].values()), "class coverage"
    t = 0
    for r, v in ch["cls"].items():
        assert v[0] == (hi - r) // M - (lo - 1 - r) // M, "count mismatch for class %d" % r
        t += v[0]
    tot.append(t)
print("candidates per chunk:", tot)
print("candidates in all:", sum(tot))
print("survivors:", sum(c["surv"] for c in chunks.values()))
'@ | Set-Content -Encoding utf8 erdos647_part4_logs.py
python erdos647_part4_logs.py erdos647
```

macOS or Linux (bash):

```bash
cat > erdos647_part4_logs.py <<'EOF'
# Problem 647, part 4: the sieve-log bookkeeping.  Usage: python erdos647_part4_logs.py erdos647
import os, sys
M = 6350400
d = sys.argv[1]
classes = [int(s) for s in open(os.path.join(d, "classes_d0.txt")).read().split()]
chunks = {}
for fn in sorted(os.listdir(d)):
    if not fn.startswith("prod_"):
        continue
    hdr, done, bad = None, False, False
    for line in open(os.path.join(d, fn)):
        if line.startswith("# sieve647"):
            hdr = dict(kv.split("=", 1) for kv in line.split()[2:])
        elif line.startswith("# DONE"):
            done = True
        elif line.startswith("S"):
            bad = True
        elif line.startswith("C "):
            f = line.split()
            r, c, s1, s2 = int(f[1]), int(f[3]), int(f[5]), int(f[7])
            ch = chunks.setdefault((int(hdr["nlo"]), int(hdr["nhi"])), {"cls": {}, "surv": 0})
            ch["cls"].setdefault(r, []).append(c)
            ch["surv"] += s1 + s2
    assert hdr and done and not bad, fn
keys = sorted(chunks)
print("chunks:", keys)
print("contiguous from 10^8+1 to 10^14:", keys[0][0] == 10**8 + 1 and keys[-1][1] == 10**14 and all(a[1] + 1 == b[0] for a, b in zip(keys, keys[1:])))
tot = []
for lo, hi in keys:
    ch = chunks[(lo, hi)]
    assert set(ch["cls"]) == set(classes) and all(len(v) == 1 for v in ch["cls"].values()), "class coverage"
    t = 0
    for r, v in ch["cls"].items():
        assert v[0] == (hi - r) // M - (lo - 1 - r) // M, "count mismatch for class %d" % r
        t += v[0]
    tot.append(t)
print("candidates per chunk:", tot)
print("candidates in all:", sum(tot))
print("survivors:", sum(c["surv"] for c in chunks.values()))
EOF
python3 erdos647_part4_logs.py erdos647
```

You should see:

```
chunks: five pairs from (100000001, 10000000000) to (30000000000001, 100000000000000)
contiguous from 10^8+1 to 10^14: True
candidates per chunk: [3437500, 343750000, 3125000000, 6944444444, 24305555556]
candidates in all: 34722187500
survivors: 0
```

What a match shows, and what it does not: It checks the logs' bookkeeping (every class once per chunk, exact counts, no survivors). It does not re-run the sieve, so it does not show that the sieve is right.

Cost: seconds.

## Step 9: Problem 647 part 3: the scan from 6,350,464 to 10^9 (345,017 candidates, each must have a k with tau(n-k) > k+2).

Files used (SHA-256):
- https://gocheckyourself.org/data/files/erdos-problems/certificates/erdos647/classes_d0.txt  86941dca4571c797c958b7f268449c49d1677ea41290482c53b4203bc6b7f5eb

Windows PowerShell:

```powershell
@'
# Problem 647, part 3: for every n in (6,350,464, 10^9] in one of the 2,205 classes, find k with tau(n-k) > k+2.
# Usage: python erdos647_part3_scan.py erdos647/classes_d0.txt
import sys
M = 6350400
classes = [int(s) for s in open(sys.argv[1]).read().split()]

def primes_upto(n):
    s = bytearray([1]) * (n + 1); s[0:2] = b"\x00\x00"
    for i in range(2, int(n ** 0.5) + 1):
        if s[i]:
            s[i * i::i] = bytearray(len(s[i * i::i]))
    return [i for i in range(n + 1) if s[i]]

def is_prime(n):                                   # Miller-Rabin, exact for n < 3.3e24
    if n < 2: return False
    for p in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37):
        if n % p == 0: return n == p
    d, s = n - 1, 0
    while d % 2 == 0: d //= 2; s += 1
    for a in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37):
        x = pow(a, d, n)
        if x in (1, n - 1): continue
        for _ in range(s - 1):
            x = x * x % n
            if x == n - 1: break
        else:
            return False
    return True

def tau_lower(n, primes):
    """exact exponent factors for the listed primes, then 2 for a prime cofactor, 3 for a composite cofactor"""
    b = 1
    for p in primes:
        if p * p > n: break
        if n % p == 0:
            e = 0
            while n % p == 0: n //= p; e += 1
            b *= e + 1
    return b if n == 1 else b * (2 if is_prime(n) else 3)

small, large = primes_upto(60), primes_upto(40000)
lo, hi = 6350464, 10**9
cand = bad = 0
for blk in range(lo // M, hi // M + 1):
    for c in classes:
        n = blk * M + c
        if n <= lo or n > hi: continue
        cand += 1
        if not any(tau_lower(n - k, small) > k + 2 for k in range(1, 65)) and \
           not any(tau_lower(n - k, large) > k + 2 for k in range(1, 65)):
            bad += 1
print("candidates:", cand)
print("candidates with no k such that tau(n-k) > k+2:", bad)
'@ | Set-Content -Encoding utf8 erdos647_part3_scan.py
python erdos647_part3_scan.py erdos647/classes_d0.txt
```

macOS or Linux (bash):

```bash
cat > erdos647_part3_scan.py <<'EOF'
# Problem 647, part 3: for every n in (6,350,464, 10^9] in one of the 2,205 classes, find k with tau(n-k) > k+2.
# Usage: python erdos647_part3_scan.py erdos647/classes_d0.txt
import sys
M = 6350400
classes = [int(s) for s in open(sys.argv[1]).read().split()]

def primes_upto(n):
    s = bytearray([1]) * (n + 1); s[0:2] = b"\x00\x00"
    for i in range(2, int(n ** 0.5) + 1):
        if s[i]:
            s[i * i::i] = bytearray(len(s[i * i::i]))
    return [i for i in range(n + 1) if s[i]]

def is_prime(n):                                   # Miller-Rabin, exact for n < 3.3e24
    if n < 2: return False
    for p in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37):
        if n % p == 0: return n == p
    d, s = n - 1, 0
    while d % 2 == 0: d //= 2; s += 1
    for a in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37):
        x = pow(a, d, n)
        if x in (1, n - 1): continue
        for _ in range(s - 1):
            x = x * x % n
            if x == n - 1: break
        else:
            return False
    return True

def tau_lower(n, primes):
    """exact exponent factors for the listed primes, then 2 for a prime cofactor, 3 for a composite cofactor"""
    b = 1
    for p in primes:
        if p * p > n: break
        if n % p == 0:
            e = 0
            while n % p == 0: n //= p; e += 1
            b *= e + 1
    return b if n == 1 else b * (2 if is_prime(n) else 3)

small, large = primes_upto(60), primes_upto(40000)
lo, hi = 6350464, 10**9
cand = bad = 0
for blk in range(lo // M, hi // M + 1):
    for c in classes:
        n = blk * M + c
        if n <= lo or n > hi: continue
        cand += 1
        if not any(tau_lower(n - k, small) > k + 2 for k in range(1, 65)) and \
           not any(tau_lower(n - k, large) > k + 2 for k in range(1, 65)):
            bad += 1
print("candidates:", cand)
print("candidates with no k such that tau(n-k) > k+2:", bad)
EOF
python3 erdos647_part3_scan.py erdos647/classes_d0.txt
```

You should see:

```
candidates: 345017
candidates with no k such that tau(n-k) > k+2: 0
```

What a match shows, and what it does not: It depends on the residue lemma (part 1). The chapter's near miss 604517614941240 (fails at k = 14, not before) is a separate check you can add.

Cost: about 5 to 30 seconds.

## Step 10: Problem 64, generator logs: 695 parts for orders 4 to 22, all reporting 0, the order-24 anchor reporting 4.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/erdos-problems/certificates/erdos64/parts_n04-21.txt  8e188165fed2df09d815a698389f46b9411ff8da2e542b6bb0f538096fcab7ea
- https://gocheckyourself.org/data/files/erdos-problems/certificates/erdos64/parts_n22.txt  6a7e21b4ed7ea31ae8c5c560a5b6a2d3c7619af2e58606905096956340f864e3

Commands (same on both platforms; not run by us unless stated):

```
No copy-paste script yet. Write it yourself from the written recipe:
Chapter heading 'Recipe for problem 64: the generator logs'. Each line of the two part files is: part name | the generator's start line | its last line; lines starting with # are comments.
```

You should see:

```
695 parts for orders 4 to 22 (184 lines in parts_n04-21.txt, one of them the order-24 anchor, and 512 in parts_n22.txt), every one reporting '0 graphs generated', and the anchor reporting '4 graphs generated'.
```

What a match shows, and what it does not: It checks the bookkeeping of the logs: that every part ran to the end and reported nothing. It does not re-run the generator; re-running it (nauty geng, free) is the independent check, and order 22 took many CPU hours.

Cost: under a second.

## Step 11: Problem 64, small orders: no connected graph with minimum degree 3 and no 4-cycle lacks an 8-cycle, for n = 4 to 15.

Commands (same on both platforms; not run by us unless stated):

```
No copy-paste script yet. Write it yourself from the written recipe:
Chapter heading 'Recipe for problem 64: the small orders and the 24-vertex graphs'. Needs an enumerator such as nauty geng (free, from its authors).
```

You should see:

```
Nothing left after discarding graphs with an 8-cycle, for n = 4 to 15; sanity counts 0 at order 9, 5 at order 10, then 9, 57, 503, 6059, 91433 for orders 11 to 15.
```

What a match shows, and what it does not: It does not cover order 16 or above.

Cost: about 30 to 50 seconds to order 15; order 16 adds minutes (the book's timing).

## Step 12: See for yourself that a one-byte change is caught: change one byte in a copy of erdos647/prod_1e8_1e10.txt and look at the fingerprint.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/erdos-problems/certificates/erdos647/prod_1e8_1e10.txt  5ede4baaf2aed587c08998855eff71e714c6cef45bd1b523d61d0e24970d7cb0

Windows PowerShell:

```powershell
python -c "b=bytearray(open('erdos647/prod_1e8_1e10.txt','rb').read()); b[0]^=1; open('tampered.copy','wb').write(b)"
"published : 5ede4baaf2aed587c08998855eff71e714c6cef45bd1b523d61d0e24970d7cb0"
"your copy : " + (Get-FileHash -Algorithm SHA256 tampered.copy).Hash.ToLower()
```

macOS or Linux (bash):

```bash
python3 -c "b=bytearray(open('erdos647/prod_1e8_1e10.txt','rb').read()); b[0]^=1; open('tampered.copy','wb').write(b)"
echo "published : 5ede4baaf2aed587c08998855eff71e714c6cef45bd1b523d61d0e24970d7cb0"
echo "your copy : $( (sha256sum tampered.copy 2>/dev/null || shasum -a 256 tampered.copy) | cut -c1-64 )"
```

You should see:

```
Two different 64-digit values; the 'published' value ends 970d7cb0 and your copy's value is different.
```

What a match shows, and what it does not: It shows the fingerprint step would notice that change. It says nothing about the file you did not change.

Cost: instant.

