Beispiel #1
0
def practical():
    """
    Practical Numbers: Positive integers with factors that can be summed to any smaller positive integer\n
    OEIS A005153
    """
    
    def srinivasan_ineq(a):
        F = prime_factorization(a)
        C = Counter(F)
        P = 2**(C[2]+1)-1
        del C[2]
        
        for p,n in C.items():
            if p > P+1:
                return False
            
            P *= (p**(n+1)-1)//(p-1)
        
        return True
    
    yield 1
    
    for a in arithmetic(2,2):
        if srinivasan_ineq(a):
            yield a
Beispiel #2
0
def selfridge():
    """
    Selfridge's Sequence: Used for parameter selection in Lucas pseudoprime tests\n
    OEIS 
    """

    for s, n in zip(sign_sequence(1), arithmetic(5, 2)):
        yield s * n
Beispiel #3
0
def nonadditive():
    """
    No term is the sum of any previous distinct pair\n
    OEIS A033627
    """

    yield 1
    yield 2

    for a in arithmetic(4, 3):
        yield a
def square():
    """
    Square Numbers\n
    OEIS A000290
    """

    S = 0

    for a in arithmetic(1, 2):
        yield S
        S += a
def oblong():
    """
    Oblong Numbers (sometimes Pronic Numbers): Sums of consecutive non-negative integers\n
    OEIS A002378
    """

    S = 0

    for a in arithmetic(2, 2):
        yield S

        S += a
def e_cfrac():
    """
    Terms of the simple continued fraction of Euler's Number
    OEIS A003417
    """

    M = arithmetic(2, 2)

    yield 2

    while True:
        yield 1
        yield next(M)
        yield 1
def rectangular(d):
    """
    Rectangular Numbers: Generalization of Oblong Numbers\n
    OEIS A005563, A028552, A028347, A028557, A028560, A028563, A028566,
         A028569, A098603, A119412, A132759, A098847-A098850, A120071,
         A132760-A132773
    """

    S = 0

    require_integers(["d"], [d])
    require_geq(["d"], [d], 1)

    for a in arithmetic(d + 1, 2):
        yield S

        S += a
Beispiel #8
0
def prime_product(P, inclusive=False):
    """
    Naturals such that all prime factors are in the set P
    
    Args:
        P -- an interable consisting of primes
        inclusive -- bool, if True only numbers divisible by all elements of P are included
    
    OEIS
    """

    require_iterable(["P"], [P])

    P = set(P)
    I = prod(P)

    for p in P:
        if not isprime(p):
            raise Exception(
                f"All elements of P must be prime, {p} is not prime")

    if inclusive:
        for n in arithmetic(I, I):
            m = n

            for p in P:
                while m % p == 0:
                    m //= p

            if m == 1:
                yield n

    else:
        for n in naturals(2):
            m = n

            for p in P:
                while m % p == 0:
                    m //= p

            if m == 1:
                yield n
Beispiel #9
0
def lucky():
    """
    Lucky Numbers: Prime-like integers resulting from a modified sieve of Eratosthenes\n
    OEIS A000959
    """

    yield 1
    yield 3

    # Terms of the sequence and where in the cycle each is
    terms = [3]
    ctrs = [2]

    # Update the cycles positions
    # If any cycle has reached zero we're not at a lucky number and no later
    # cycles will be updated since the value has been sieved out before that
    # number is known
    def update():
        for n, t in enumerate(terms):
            ctrs[n] = (ctrs[n] + 1) % t
            if ctrs[n] == 0:
                return False
        return True

    # Which lucky number we're currently looking for
    # This sets where the cycle for a newly found lucky number begins
    nth = 3

    # Go through the odds greater than 5 looking for lucky numbers
    for o in arithmetic(5, 2):
        if update():
            yield o

            terms.append(o)
            ctrs.append(nth)
            nth += 1