"""Minimal number of successor states needed to reproduce an entire cyclic sieve word."""
from math import gcd,prod,isqrt
import json

def run():
    primes=(2,3,5,7,11);R=prod(primes)
    word=bytes(gcd(x,R)==1 for x in range(R))
    # A shift defines a period iff it preserves a full cycle.
    periods=[d for d in range(1,R+1) if word[d:]+word[:d]==word]
    assert periods==[R]
    # Different infinite tails can be separated by successively refining the current output.
    states=list(word);horizon=1
    while len(set(states))<R:
        names={};states=[names.setdefault((states[i],word[(i+horizon)%R]),len(names)) for i in range(R)]
        assert len(names)>1
        horizon+=1
    def state(x):return x%30,x%7==0,x%11==0,(x+1)%11==0
    failed=next((x,y) for x in range(701,1101) for y in range(x+1,1101) if state(x)==state(y) and state(x+1)!=state(y+1))
    prime=lambda x:x>=2 and all(x%k for k in range(2,isqrt(x)+1))
    counts=[sum(map(prime,range(2,x+1))) for x in (700,1100)]
    false=next(x for x in range(701,1101) if word[x%R] and not prime(x))
    return dict(period=R,survivors=sum(word),last_separating_length=horizon,heldout=[701,1100],collision=failed,first_false=false,pi=counts)
if __name__=='__main__':print(json.dumps(run(),indent=2))
