()
Generate pairs n,F where F is the prime factorization of n.
    F is represented as a dictionary in which each prime factor of n
    is a key and the exponent of that prime is the corresponding value.
Generate pairs n,F where F is the prime factorization of n.
    F is represented as a dictionary in which each prime factor of n
    is a key and the exponent of that prime is the corresponding value.
Generate pairs n F where F is the prime factorization of n . F is represented as a dictionary in which each prime factor of n is a key and the exponent of that prime is the corresponding value .
def FactoredIntegers():
    """
    Generate pairs n,F where F is the prime factorization of n.
    F is represented as a dictionary in which each prime factor of n
    is a key and the exponent of that prime is the corresponding value.
    """
    yield 1,{}
    i = 2
    factorization = {}
    while True:
        if i not in factorization:  # prime
            F = {i:1}
            yield i,F
            factorization[2*i] = F
        elif len(factorization[i]) == 1:    # prime power
            p, x = next(iter(factorization[i].items()))
            F = {p:x+1}
            yield i,F
            factorization[2*i] = F
            updateDict(factorization, i+p**x, p, x)
            del factorization[i]
        else:
            yield i,factorization[i]
            for p,x in factorization[i].items():
                q = p**x
                iq = i+q
                if iq in factorization and p in factorization[iq]:
                    iq += p**x  # skip higher power of p
                updateDict(factorization, iq, p, x)

            del factorization[i]
        i += 1
def FactoredIntegers ( ) : yield 1 , { } i = 2 factorization = { } while True : if i not in factorization : # prime F = { i : 1 } yield i , F factorization [ 2 * i ] = F elif len ( factorization [ i ] ) == 1 : # prime power p , x = next ( iter ( factorization [ i ] . items ( ) ) ) F = { p : x + 1 } yield i , F factorization [ 2 * i ] = F updateDict ( factorization , i + p ** x , p , x ) del factorization [ i ] else : yield i , factorization [ i ] for p , x in factorization [ i ] . items ( ) : q = p ** x iq = i + q if iq in factorization and p in factorization [ iq ] : iq += p ** x # skip higher power of p updateDict ( factorization , iq , p , x ) del factorization [ i ] i += 1