def miller_rabin_d(n: int) -> bool: 
    """Check if n is a prime number via deterministic Miller-Rabin test.

    Miller showed that it is possible to make the algorithm deterministic by 
    only checking all bases ≤ O(lg(n)^2). Bach later gave a concrete bound, it 
    is only necessary to test all bases a ≤ 2lg(n)^2. It turns out, for testing 
    a 32 bit integer it is only necessary to check the first 4 prime bases: 
    2, 3, 5 and 7. The smallest composite number that fails this test is 
    3,215,031,751=151⋅751⋅28351. And for testing 64 bit integer it is enough to 
    check the first 12 prime bases: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, and 
    37."""

    if n < 2: return False 
    s, d = 0, n-1
    while d&1 == 0:
        s += 1
        d >>= 1
    for a in 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37:
        if n == a: return True
        v = pow(a, d, n) 
        if v != 1 and v != n-1:
            for j in range(1, s): 
                v = pow(v, 2, n)
                if v == n-1: break 
            if v != n-1: return False 
    return True