"""Exploration: on top of S5 (halving + B' + D + D' + D''), test merge families
F1: d in (x/7, x/6], gcd(d,6)=1, F(d)<=x : {3d,4d,5d} -> d
F2/F3: d in (x/11, x/7], gcd(d,6)=1, F(d)<=x : {3d,4d,5d,7d} -> d  (split by P^-(d))
Report: for each candidate, whether the expected multiples are in S, d not in S, and conflicts are exactly them."""
import sys, math
from math import gcd
from collections import Counter
x = int(sys.argv[1])
exec(open('combine_check.py').read().split("L = math.log(x)")[0].replace("x = int(sys.argv[1])", ""))
L = math.log(x)
def v2(n): return (n & -n).bit_length() - 1
S = set(S2)
for d in [d for d in range(x // 4 + 1, x // 3 + 1) if d % 2 == 1 and F[d] <= x]: S -= {2*d, 3*d}; S.add(d)
for d in [d for d in range(x // 5 + 1, x // 4 + 1) if d % 2 == 1 and F[d] <= x]: S -= {2*d, 3*d}; S.add(d)
for d in [d for d in range(x // 5 + 1, 2 * x // 9 + 1) if d % 2 == 0 and v2(d) >= 2 and F[d >> v2(d)] <= x]: S -= {2*d, 3*d}; S.add(d)
divs = None
def conflicts(d, S):
    out = set()
    for g in range(1, int(d ** 0.5) + 1):
        if d % g: continue
        for gg in {g, d // g}:
            lim = x * gg // d
            for b in range(gg, lim + 1, gg):
                if b in S and b != d and d * b // gcd(d, b) <= x: out.add(b)
    return out
res = Counter(); ok = {}
for d in range(x // 11 + 1, x // 6 + 1):
    if gcd(d, 6) != 1 or F[d] > x: continue
    ks = (3, 4, 5) if 7 * d > x else (3, 4, 5, 7)
    exp = {k * d for k in ks}
    conf = conflicts(d, S)
    good = d not in S and exp <= S and conf == exp
    key = (ks, spf[d], round(x / d, 1) if not good else "ok")
    res[(ks, spf[d], good)] += 1
    if not good and res[(ks, spf[d], good)] <= 3: print("fail", d, round(x / d, 3), spf[d], sorted(conf - exp)[:5], sorted(exp - S)[:5], d in S)
    ok.setdefault((ks, spf[d], good), []).append(x / d)
for k, v in sorted(res.items(), key=lambda t: str(t[0])):
    r = ok[k]; print(k, v, f"x/d in [{min(r):.2f},{max(r):.2f}]")
