This site is supported by donations to The OEIS Foundation.

User:R. J. Mathar/oeisPy/oeisPy/oeis core.py

From OeisWiki
Jump to: navigation, search
""" Native python3.1 implementations of OEIS http://oeis.org/classic functions.

==usage==
python3
>>> from oeisPy import *

The generic common format for function calls is

Axxxxx(n) returns the n-th item of the sequence, where n is defined as usual
depending on the offset. The first meaningful number is Axxxxxx(offset).

Axxxxxx(n,k) returns the item in row n, column k of a triangle or array.

Axxxxxx_list(n) returns a list with n items, starting with Axxxxxx(offset).

Axxxxxx_row(n) returns all members of the n-th row of the sequence. The
topmost row is obtained by Axxxxx_row(offset).

isAxxxxxx(n) returns True or False depending on whether n is in the sequence
or not.

==author==
Richard J. Mathar, http://www.strw.leidenuniv.nl/~mathar/progs/oeisPy-0.0.1.tar.gz
"""
from nzmath import *
import oeisPy.oeis_bulk as oeis_bulk
import oeisPy.oeis_trans as oeis_trans

def A000005(n):
        """ tau(.), the number of divisors of the argument.
        This function returns tau(n), the number of divisors of n.

        ==input==
        n -- positive integer

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A000005(6)
        4
        >>>oeis_core.A000005(100)
        9
        >>>oeis_core.A000005(51)
        4
        >>>oeis_core.A000005(1)
        1

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return multiplicative.sigma(0,n)

def A000005_list(n):
        """ The first n tau(.).
        This function returns the list of tau(1..n).

        ==input==
        n -- integer >=0.

        ==output==
        list -- The list starting [1, 2, 2, 3, 2, 4, 2, 4, 3, 4, 2..]

        ==examples==
        >>>oeis_core.A000005_list(6)
        [1, 2, 2, 3, 2, 4]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return [A000005(i) for i in range(1,n+1)]

def A000009(n):
        """ Number of partitions into distinct parts.
        This function returns the number of partitions of the argument into
        distinct parts, or, the number of its partitions into odd parts.

        ==input==
        n -- integer >=0.

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A000009(0)
        1
        >>>oeis_core.A000009(6)
        4
        >>>oeis_core.A000009(26)
        165

        ==author==
        Richard J. Mathar 2010-07-03
        """

        # not implemented because some next() attribute isn't implemented in the nzmath library
        if False:
                f = {0: 1}  # represents the polynomial 1 = 1*x**0
                d = poly.formalsum.DictFormalSum(f,0)
                p = poly.uniutil.IntegerPolynomial(d,rational.theIntegerRing)
                for m in range(1,n+1):
                        f = {0: 1, m : 1}
                        d = poly.formalsum.DictFormalSum(f,0)
                        pm = poly.uniutil.IntegerPolynomial(d,rational.theIntegerRing)
                        p = p.ringmul(pm)
                return p[n]
        return A000009_list(n+1)[n]

def A000009_list(n):
        """ List of number of partitions into distinct parts.

        ==input==
        n -- integer >=0.

        ==output==
        list -- The first n values of [1, 1, 1, 2, 2, 3, 4, 5, 6, 8, 10, 12..]

        ==examples==
        >>>oeis_core.A000009_list(0)
        []
        >>>oeis_core.A000009_list(5)
        [1, 1, 1, 2, 2]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n < 0:
                return []
        a = [1,1,1]
        if n <=3 :
                return a[0:n]
        while len(a)<n:
                i = len(a)
                b = 0
                for k in range(1,i+1):
                        b += A000593(k)*a[i-k]
                a.append(b//i)
        return a
def A000010(n):
        """ Euler's totient function phi(.).
        This function returns phi(n), the Euler totient function

        ==input==
        n -- positive integer

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A000010(11)
        10

        >>>oeis_core.A000010_list(10)
        [1, 1, 2, 2, 4, 2, 6, 4, 6, 4]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return multiplicative.euler(n)

def A000010_list(n):
        return [A000010(i) for i in range(1,n+1)]


def A000012(n):
        """ Constant 1.
        This function returns 1.

        ==input==
        n -- positive integer >=0 .

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A000012(11)
        1

        >>>oeis_core.A000012_list(10)
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return 1

def A000012_list(n):
        return [A000012(i) for i in range(n)]
def A000027(n):
        """ Copy of the argument.

        This function returns the argument itself.

        ==input==
        n -- positive integer >=0 .

        ==output==
        integer -- n again.

        ==examples==
        >>>oeis_core.A000027(11)
        11

        >>>oeis_core.A000027_list(10)
        [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return n

def A000027_list(n):
        return [i for i in range(1,n+1)]

def A000032(n):
        """ Lucas numbers.
        This function returns L(n), n-th Lucas number, starting 2, 1, 3, 4,...

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- Lucas(n)

        ==examples==
        >>>oeis_core.A000032(0)
        2
        >>>oeis_core.A000032(1)
        1
        >>>oeis_core.A000032(2)
        3
        >>>oeis_core.A000032(3)
        4

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return oeis_trans.linRec([2,1],[1,1],n)

def A000032_list(n):
        """ List of Lucas numbers up to some small index.
        This function returns a list of the first Lucas(.)

        ==input==
        n -- integer >0 .

        ==output==
        list -- Lucas(0) up to Lucas(n-1)

        ==examples==
        >>>oeis_core.A000032_list(10)
        [2, 1, 3, 4, 7, 11, 18, 29, 47, 76]

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return oeis_trans.linRec_list([2,1],[1,1],n)

def isA000032(n):
        """ Test the argument for being a Lucas number.
        This function True or False depending on n being in A000032.

        ==input==
        n -- integer >=0 .

        ==output==
        boolean -- False for negative numbers, True for one of 1, 2, 3, 4, 7, 11 etc

        ==examples==
        >>>oeis_core.isA000032(0)
        False
        >>>oeis_core.isA000032(1)
        True
        >>>oeis_core.isA000032(2)
        True
        >>>oeis_core.isA000032(3)
        True

        ==author==
        Richard J. Mathar 2010-07-01
        """
        if n <= 0:
                return False
        if n < 5:
                return True
        L = [2,1,3]
        while L[2] < n:
                L[0:1] = []
                L.append(L[1]+L[0])
        return (L[2] ==n)

def A000040(n):
        """ The prime at the index provided by the argument.
        This function returns the n-th prime

        ==input==
        n -- integer >=1 .

        ==output==
        integer -- prime(n)

        ==examples==
        >>>oeis_core.A000040(3)
        5

        >>>oeis_core.A000040_list(10)
        [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return prime.prime(n)

def A000040_list(n):
        """ The first n primes.
        This functin provides a list of the first n primes, starting [2,3,5,7,..]

        ==input==
        n -- integer >=1 .

        ==output==
        list -- The first n terms of [2,3,5,7,11,13,17,19,...]

        ==examples==
        >>>oeis_core.A000040_list(3)
        [2, 3, 5]
        """
        # return [A000040(i) for i in range(1,n+1)] # the slow variant
        a =[]
        p = 2
        while len(a) < n:
                a.append(p)
                p = prime.nextPrime(p)
        return a

def isA000040(n):
        """
        This function tests for primality.

        ==input==
        n -- integer >=1 .

        ==output==
        True or False

        ==examples==
        >>>oeis_core.isA000040(3)
        True

        >>>oeis_core.isA000040(890983)
        False

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return prime.primeq(n)

def A000041(n):
        """
        This function returns the partition number of n

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- number of partitions of n

        ==examples==
        >>>oeis_core.A000041(3)
        3

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return combinatorial.partition_number(n)

def A000041_list(n):
        """ List of parition numbers.
        This function returns the first n partition numbers.

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- number of partitions of n

        ==examples==
        >>>oeis_core.A000041_list(10)
        [1, 1, 2, 3, 5, 7, 11, 15, 22, 30]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return [A000041(i) for i in range(n)]

def A000043(n):
        """ Prime exponents of the n-th Mersenne prime.
        This function returns a prime p such that 2**p-1 is a Mersenne prime.
        This is not computed but simply taken from a static lookup table.

        ==input==
        n -- integer >0 .

        ==output==
        integer -- the prime exponent in the power of 2 that generates a Mersenne prime

        ==examples==
        >>>oeis_core.A000043(3)
        5
        >>>oeis_core.A000043(4)
        7

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return A000043_list(n)[-1]

def A000043_list(n):
        """ Prime exponents of the Mersenne primes.
        A list of prime epxonents that generate Mersenne primes.
        This is not computed but simply taken from a static lookup table.

        ==input==
        n -- integer >0 .

        ==output==
        list -- the first n prime exponents [2,3,5,7,13,..]

        ==examples==
        >>>oeis_core.A000043_list(10)
        [2, 3, 5, 7, 13, 17, 19, 31, 61, 89]

        ==author==
        Richard J. Mathar 2010-07-02
        """
        a = [2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279,
                2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701,
                23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433,
                1257787, 1398269, 2976221, 3021377, 6972593, 13466917]
        if n <= len(a):
                return a[0:n]
        else:
                raise LookupError('Requested '+str(n)+' outsided tabulated range')

def A000045(n):
        """ Fibonacci numbers.
        This function returns the n-th Fibonacci number

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- Fibonacci(n)

        ==examples==
        >>>oeis_core.A000045(0)
        0
        >>>oeis_core.A000045(1)
        1
        >>>oeis_core.A000045(2)
        1

        ==author==
        Richard J. Mathar 2010-06-29
        """
        if n < 2:
                return n
        else:
                return A000045(n-1)+A000045(n-2)

def A000045_list(n):
        """ List of the small Fibonacci numbers.
        This function returns the truncated list of the Fibonacci numbers 0,1,1,2,3,...

        ==input==
        n -- integer >=0 .

        ==output==
        list -- The first n values of [0,1,1,2,3,...]

        ==examples==
        >>>oeis_core.A000045_list(10)
        [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return [A000045(i) for i in range(n)]

def isA000045(n):
        """
        This function tests for inclusion in the Fibonacci sequence

        ==input==
        n -- integer >=1 .

        ==output==
        True or False

        ==examples==
        >>>oeis_core.isA000045(3)
        True

        >>>oeis_core.isA000045(4)
        False

        >>>oeis_core.isA000045(890983)
        False

        >>>oeis_core.isA000045(39088169)
        True

        ==author==
        Richard J. Mathar 2010-06-29
        """
        if n < 0:
                return False
        elif n < 4:
                return True
        else:
                fo = 2
                fim = 3
                fi = 5
                while fi <= n:
                        if fi == n:
                                return True
                        fo = fim
                        fim = fi
                        fi += fo
                return False

def A000079(n):
        """
        This function returns the n-th power of 2.

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- 2**n

        ==examples==
        >>>oeis_core.A000079(0)
        1

        >>>oeis_core.A000079(3)
        8

        >>>oeis_core.A000079_list(9)
        [1, 2, 4, 8, 16, 32, 64, 128, 256]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        if n < 0:
                return 0
        else:
                return 2**n

def A000079_list(n):
        return [A000079(i) for i in range(n)]

def isA000079(n):
        """
        This function tests the argument against being a power of 2.

        ==input==
        n -- integer

        ==output==
        True or False

        ==examples==
        >>>oeis_core.isA000079(1)
        True

        >>>oeis_core.isA000079(4)
        True

        >>>oeis_core.isA000079(15)
        False

        ==author==
        Richard J. Mathar 2010-06-29
        """
        if n < 1:
                return False
        else:
                a = 0
                nshft = n
                while nshft > 0:
                        a += nshft % 2
                        nshft >>= 1
                        if a >1:
                                return False
                return True

def A000081(n):
        """ List of count of rooted trees with n nodes.

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- the value

        ==examples==
        >>>oeis_core.A000081(6)
        20

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return A000081_list(n+1)[-1]

def A000081_list(n):
        """ List of count of rooted trees with k nodes, k =0 up to n-1

        ==input==
        n -- integer >=0 .

        ==output==
        list -- The first n values of 0, 1, 1, 2, 4, 9, 20, 48, 115,...

        ==examples==
        >>>oeis_core.A000081_list(8)
        [0, 1, 1, 2, 4, 9, 20, 48]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        a = [0,1,1]
        if n <= 3:
                return a[:n]
        while len(a)<n:
                anxt =0
                i = len(a)
                for k in range(1,i):
                        dsu = 0
                        for d in factor.misc.allDivisors(k):
                                dsu += d*a[d]
                        anxt += dsu*a[i-k]
                a.append(anxt// (i-1))
        return a

def A000108(n):
        """ Catalan(n).
        This function returns the n-th Catalan number

        ==input==
        n -- positive integer

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A000108(11)
        58786

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return combinatorial.catalan(n)

def A000108_list(n):
        """ List of first n Catalan numbers.
        This function returns the Catalan numbers starting with [1,1,2,...]

        ==input==
        n -- positive integer

        ==output==
        list -- the first n Catalan numbers

        ==examples==
        >>>oeis_core.A000108_list(4))
        [1,1,2,5]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return [A000108(i) for i in range(n)]

def A000110(n):
        """ Bell(n).
        This function returns the n-th Bell number.

        ==input==
        n -- positive integer

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A000110(0)
        1
        >>>oeis_core.A000110(1)
        1
        >>>oeis_core.A000110(11)
        678570

        ==author==
        Richard J. Mathar 2010-07-01
        """
        # if n ==0:
        #       return 1
        # a = 0
        # for j in range(n):
        #       a += A000166(j)* combinatorial.binomial(n-1,j) *(n-j)**(n-1)
        # return (a // combinatorial.factorial(n-1) )
        return combinatorial.bell(n)

def A000110_list(n):
        """ List of the first n Bell numbers.
        This function returns the Bell numbers starting with [1,1,2,5,15...]

        ==input==
        n -- positive integer

        ==output==
        list -- the first n Bell numbers

        ==examples==
        >>>oeis_core.A000110_list(6)
        [1,1,2,5,15,52]

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return [A000110(i) for i in range(n)]

def A000120(n):
        """ Hamming weight (number of 1's in the binary representation).
        This function returns Hamming(n).

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- number of bits set in the binary representation.
        Set to zero for negative n.

        ==examples==
        >>>oeis_core.A000120(3)
        2
        >>>oeis_core.A000120(4)
        1

        ==author==
        Richard J. Mathar 2010-07-01
        """
        if n < 1:
                return 0
        else:
                a = 0
                nshft = n
                while nshft > 0:
                        a += nshft & 1
                        nshft >>= 1
                return a

def A000120_list(n):
        """ List of the first binary weights.
        This function returns the binary weights starting with [0,1,1,2,1,...]

        ==input==
        n -- positive integer

        ==output==
        list -- the first n Hamming weights.

        ==examples==
        >>>oeis_core.A000120_list(7)
        [0, 1, 1, 2, 1, 2, 2]

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return [A000120(i) for i in range(n)]

def A000124(n):
        """ n*(n+1)/2+1.
        Lazy caterer's sequence at index n.

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- 1+n*(n+1)/2

        ==examples==
        >>>oeis_core.A000124(0)
        1
        >>>oeis_core.A000124(1)
        2
        >>>oeis_core.A000124(5)
        16

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return 1+n*(n+1)//2

def A000124_list(n):
        """ The list of k*(k+1)/2+1 for k>=0.

        ==input==
        n -- integer >=0 .

        ==output==
        list -- The frist n term sof [1,2,4,7,11,..]

        ==examples==
        >>>oeis_core.A000124_list(5)
        [1, 2, 4, 7, 11]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return [1+i*(i+1)//2 for i in range(n)]

def A000129(n):
        """ Pell numbers.
        This function returns Pell(n), n-th Pell number, starting 0, 1, 2, 5.

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- Pell(n)

        ==examples==
        >>>oeis_core.A000129(0)
        0
        >>>oeis_core.A000129(1)
        1
        >>>oeis_core.A000129(2)
        2
        >>>oeis_core.A000129(6)
        70

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return oeis_trans.linRec([0,1],[2,1],n)

def A000129_list(n):
        """ List of Pell numbers up to some small index.
        This function returns a list of the first Pell(.)

        ==input==
        n -- integer >0 .

        ==output==
        list -- Pell(0) up to Pell(n-1)

        ==examples==
        >>>oeis_core.A000129_list(10)
        [0, 1, 2, 5, 12, 29, 70, 169, 408, 985]

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return oeis_trans.linRec_list([0,1],[2,1],n)

def isA000129(n):
        """ Test the argument for being a Pell number.
        This function True or False depending on n being in A000129.

        ==input==
        n -- integer >=0 .

        ==output==
        boolean -- False for negative numbers, True for one of 0,1,2,5,12,...

        ==examples==
        >>>oeis_core.isA000129(0)
        True
        >>>oeis_core.isA000129(1)
        True
        >>>oeis_core.isA000129(2)
        True
        >>>oeis_core.isA000129(3)
        False

        ==author==
        Richard J. Mathar 2010-07-01
        """
        if n < 0:
                return False
        if n < 3:
                return True
        P = [0,1,2]
        while P[2] < n:
                P[0:1] = []
                P.append(2*P[1]+P[0])
        return (P[2] ==n)

def A000142(n):
        """ factorial
        This function returns n!

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- factorial(n)

        ==examples==
        >>>oeis_core.A000142(3)
        6

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return combinatorial.factorial(n)

def A000166(n):
        """ Subfactorial(n)
        This function returns the n-th subfactorial.

        ==input==
        n -- nonnegative integer

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A000166(0)
        1
        >>>oeis_core.A000166(4)
        9

        ==author==
        Richard J. Mathar 2010-07-01
        """
        s = [1,0,1,2]
        if n <=3:
                return s[n]
        for i in range(4,n+1):
                s[0:1] = []
                s.append(i*s[-1]+(-1)**i)
        return s[-1]

def A000166_list(n):
        """ List of the first n subfactorials.
        This function returns the subfactorials starting with [1,0,1,2,9...]

        ==input==
        n -- positive integer

        ==output==
        list -- the first n Bell numbers

        ==examples==
        >>>oeis_core.A000166_list(6)
        [1, 0, 1, 2, 9, 44]

        ==author==
        Richard J. Mathar 2010-07-01
        """
        s = [1,0,1,2]
        if n <=4:
                return s[0:n]
        while len(s) < n:
                i = len(s)
                s.append(i*s[-1]+(-1)**i)
        return s

def A000169(n):
        """ n**(n-1).
        This function returns the number of labelled rooted trees with n nodes.

        ==input==
        n -- integer >=1

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A000166(1)
        1
        >>>oeis_core.A000166(5)
        625

        ==author==
        Richard J. Mathar 2010-07-17
        """
        return n**(n-1)

def A000203(n):
        """ sigma(n)
        This function returns the sigma(n), the sum of divisors of n.

        ==input==
        n -- positive integer

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A000203(6)
        12

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return multiplicative.sigma(1,n)

def A000203_list(n):
        """ sigma(n)
        This function returns the a list of the first sigma(n).

        ==input==
        n -- positive integer

        ==output==
        list -- The truncated list of [1, 3, 4, 7,...]

        ==examples==
        >>>oeis_core.A000203_list(4)
        [1, 3, 4, 7]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return [A000203(i) for i in range(1,n+1)]

def A000203(n):
        """ Lucas numbers.
        This function returns L(n), n-th Lucas number, starting 1, 3, 4,...

        ==input==
        n -- integer >0 .

        ==output==
        integer -- Lucas(n)

        ==examples==
        >>>oeis_core.A000203(1)
        1
        >>>oeis_core.A000203(2)
        3
        >>>oeis_core.A000203(3)
        4

        ==author==
        Richard J. Mathar 2010-07-01
        """
        if n <= 0:
                raise ValueError('non-positive argument '+str(n))
        return A000032(n)

def A000203_list(n):
        """ List of Lucas numbers up to some small index.
        This function returns a list of the first Lucas(.)

        ==input==
        n -- integer >0 .

        ==output==
        list -- Lucas(1) up to Lucas(n)

        ==examples==
        >>>oeis_core.A000203_list(9)
        [1, 3, 4, 7, 11, 18, 29, 47, 76]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        a = A000032_list(n+1)
        return a[1:]

def A000217(n):
        """ Triangular number.
        This function returns the n-th triangular number

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- n*(n+1)/2

        ==examples==
        >>>oeis_core.A000217(0)
        0
        >>>oeis_core.A000217(1)
        1
        >>>oeis_core.A000217(3)
        6

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return n*(n+1)//2

def A000217_list(n):
        """ List of the first n Triangular numbers..

        ==input==
        n -- integer >=0 .

        ==output==
        list -- n items starting [0, 1, 3, 10,..]

        ==examples==
        >>>oeis_core.A000217_list(10)
        [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return [A000217(i) for i in range(n)]

def isA000217(n):
        """
        This function tests whether the argument is a triangular number

        ==input==
        n -- integer >=1 .

        ==output==
        True or False

        ==examples==
        >>>oeis_core.isA000217(3)
        True

        >>>oeis_core.isA000217(4)
        False

        >>>oeis_core.isA000217(120)
        True

        ==author==
        Richard J. Mathar 2010-06-29
        """
        if arith1.issquare(1+8*n) ==0:
                return False
        else:
                return True

def A000225(n):
        """ 2**n-1.

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- one less than the n-th power of 2.

        ==examples==
        >>>oeis_core.A000225(3)
        7
        >>>oeis_core.A000225(0)
        0

        ==author==
        Richard J. Mathar 2010-07-01
        """
        if n < 1:
                return 0
        else:
                return 2**n -1

def A000244(n):
        """ The powers of 3.
        This function returns 3**n.

        ==input==
        n -- integer >=0.

        ==output==
        integer -- 3**n

        ==examples==
        >>>oeis_core.A000244(0)
        1
        >>>oeis_core.A000244(3)
        27
        >>>oeis_core.A000244(4)
        81

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n < 0:
                raise ValueError('negative argument '+str(n))
        return 3**n

def A000244_list(n):
        """ A list of the first n powers of 3.

        ==input==
        n -- integer >=0.

        ==output==
        list -- The list [1 ,3 ,9 ,27, 81,..] truncated to a length of n.

        ==examples==
        >>>oeis_core.A000244_list(8)
        [1, 3, 9, 27, 81, 243, 729, 2187]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return [3**i for i in range(n)]

def isA000244(n):
        """ Test whether the argument is a positive power of 3.

        ==input==
        n -- integer >=0.

        ==output==
        boolean -- True if n is of the form 3**k, k>=0.

        ==examples==
        >>>oeis_core.isA000244(729)
        True
        >>>oeis_core.isA000244(8)
        False

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n <=0:
                return False
        e = 0
        nshft = n
        while nshft >0:
                e += nshft % 3
                if e > 1:
                        return False
                nshft //= 3
        return True

def A000290(n):
        """ Squares
        This function returns the square of n.

        ==input==
        n -- integer

        ==output==
        integer -- n**2

        ==examples==
        >>>oeis_core.A000290(0)
        0

        >>>oeis_core.A000290(-9)
        81

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return n**2

def A000290_list(n):
        """ List of small squares
        This function returns the first n squares starting at 0.

        ==input==
        n -- integer

        ==output==
        list -- containing 0, 1, 4, 9 ,.. up to (n-1)**2

        >>>oeis_core.A000290_list(10)
        [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return [A000290(i) for i in range(n)]

def isA000290(n):
        """ Test against being a perfect square.
        This function checks an integer argument for being an integer squared.

        ==input==
        n -- integer

        ==output==
        True or False

        ==examples==
        >>>oeis_core.isA000290(3)
        False

        >>>oeis_core.isA000290(-4)
        False

        >>>oeis_core.isA000290(9)
        True

        ==author==
        Richard J. Mathar 2010-07-01
        """
        if n ==0:
                return True
        if arith1.issquare(n) ==0:
                return False
        else:
                return True

def A000292(n):
        """ Tetrahedral Numbers.
        This function returns n*(n+1)*(n+2)/6.

        ==input==
        n -- integer

        ==output==
        integer -- n*(n+1)*(n+2)/6.

        ==examples==
        >>>oeis_core.A000292(0)
        0
        >>>oeis_core.A000292(2)
        4
        >>>oeis_core.A000292(3)
        10

        ==author==
        Richard J. Mathar 2010-07-02
        """
        return n*(n+1)*(n+2)//6

def isA000292(n):
        """ Check the argument for being a tetrahedral number.
        This function is slow and parses the list of tetrahedral numbers with linear
        complexity in n.

        ==input==
        n -- integer

        ==output==
        boolean -- True if n can be written as k*(k+1)*(k+2)/6 with k>=0.

        ==examples==
        >>>oeis_core.isA000292(0)
        True
        >>>oeis_core.isA000292(2)
        False
        >>>oeis_core.isA000292(3)
        False

        ==author==
        Richard J. Mathar 2010-07-02
        """
        if n < 0:
                return False
        k = 0
        t = 0  # t contains 6 times the k-th tetrahedral number
        while True:
                if t == 6*n:
                        return True
                if t > 6*n:
                        return False
                k += 1
                t += 3*k*(k+1)

def A000292_list(n):
        """ List of tetrahedral numbers.
        This function returns the first n tetrahedral numbers, starting at 0.

        ==input==
        n -- integer

        ==output==
        list -- containing n elements with 0, 1, 4, 10,..

        >>>oeis_core.A000292_list(10)
        [0, 1, 4, 10, 20, 35, 56, 84, 120, 165]

        ==author==
        Richard J. Mathar 2010-07-02
        """
        return [A000292(i) for i in range(n)]
def A000302(n):
        """ The powers of 4.
        This function returns 4**n.

        ==input==
        n -- integer >=0.

        ==output==
        integer -- 4**n

        ==examples==
        >>>oeis_core.A000302(0)
        1
        >>>oeis_core.A000302(3)
        64
        >>>oeis_core.A000302(4)
        256

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n < 0:
                raise ValueError('negative argument '+str(n))
        return 4**n

def A000302_list(n):
        """ A list of the first n powers of 4.

        ==input==
        n -- integer >=0.

        ==output==
        list -- The list [1, 4, 16, 64,... truncated to a length of n.

        ==examples==
        >>>oeis_core.A000302_list(8)
        [1, 4, 16, 64, 256, 1024, 4096, 16384]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return [4**i for i in range(n)]

def isA000302(n):
        """ Test whether the argument is a positive power of 4.

        ==input==
        n -- integer >=0.

        ==output==
        boolean -- True if n is of the form 4**k, k>=0.

        ==examples==
        >>>oeis_core.isA000302(16484)
        True
        >>>oeis_core.isA000302(8)
        False

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n <=0:
                return False
        e = 0
        nshft = n
        while nshft >0:
                e += nshft % 4
                if e > 1:
                        return False
                nshft //= 4
        return True

def A000326(n):
        """ Pentagonal numbers.
        This function returns n*(3n-1)/2.

        ==input==
        n -- integer

        ==output==
        integer -- n*(3*n-1)/2.

        ==examples==
        >>>oeis_core.A000292(0)
        0
        >>>oeis_core.A000292(1)
        1
        >>>oeis_core.A000292(5)
        35

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return n*(3*n-1)//2

def isA000326(n):
        """ Test whether the argument is a pentagonal number.

        ==input==
        n -- integer

        ==output==
        boolean -- True if n is of the form k*(3k-1)/2, k>=0.

        ==examples==
        >>>oeis_core.isA000326(0)
        True
        >>>oeis_core.isA000326(2)
        False
        >>>oeis_core.isA000326(70)
        True

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n < 0:
                return False
        if n < 2:
                return True
        if arith1.issquare(1+24*n) ==0:
                return False
        else:
                return ((arith1.issquare(1+24*n)+1) %6) == 0

def A000330(n):
        """ Square pyramidal numbers.
        This function returns n*(n+1)*(2n+1)/6.

        ==input==
        n -- integer

        ==output==
        integer -- n*(n+1)*(2n+1)/6.

        ==examples==
        >>>oeis_core.A000330(0)
        0
        >>>oeis_core.A000330(2)
        5
        >>>oeis_core.A000330(3)
        14

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return n*(n+1)*(2*n+1)//6

def isA000330(n):
        """ Check the argument for being a square pyramidal number.
        This function is slow and parses the list of numbers with linear
        complexity in n.

        ==input==
        n -- integer

        ==output==
        boolean -- True if n can be written as k*(k+1)*(2*k+1)/6 with k>=0.

        ==examples==
        >>>oeis_core.isA000330(0)
        True
        >>>oeis_core.isA000330(2)
        False
        >>>oeis_core.isA000330(55)
        True

        ==author==
        Richard J. Mathar 2010-07-02
        """
        if n < 0:
                return False
        k = 0
        t = 0  # t contains 6 times the k-th square-pyramidal number
        while True:
                if t == 6*n:
                        return True
                if t > 6*n:
                        return False
                k += 1
                t += 6*k**2

def A000330_list(n):
        """ List of tetrahedral numbers.
        This function returns the first n square-pyrimidal numbers, starting at 0.

        ==input==
        n -- integer

        ==output==
        list -- containing n elements with 0, 1, 5, 14,..

        >>>oeis_core.A000330_list(10)
        [0, 1, 5, 14, 30, 55, 91, 140, 204, 285]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return [A000330(i) for i in range(n)]

def A000043(n):
        """ Prime exponents of the n-th Mersenne prime.
        This function returns a prime p such that 2**p-1 is a Mersenne prime.
        This is not computed but simply taken from a static lookup table.

        ==input==
        n -- integer >0 .

        ==output==
        integer -- the prime exponent in the power of 2 that generates a Mersenne prime

        ==examples==
        >>>oeis_core.A000043(3)
        5
        >>>oeis_core.A000043(4)
        7

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return A000043_list(n)[-1]

def A000043_list(n):
        """ Prime exponents of the Mersenne primes.
        A list of prime epxonents that generate Mersenne primes.
        This is not computed but simply taken from a static lookup table.

        ==input==
        n -- integer >0 .

        ==output==
        list -- the first n prime exponents [2,3,5,7,13,..]

        ==examples==
        >>>oeis_core.A000043_list(10)
        [2, 3, 5, 7, 13, 17, 19, 31, 61, 89]

        ==author==
        Richard J. Mathar 2010-07-02
        """
        a = [2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279,
                2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701,
                23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433,
                1257787, 1398269, 2976221, 3021377, 6972593, 13466917]
        if n <= len(a):
                return a[0:n]
        else:
                raise LookupError('Requested '+str(n)+' outsided tabulated range')

def A000312(n):
        """ The power n**n.

        ==input==
        n -- integer >=0.

        ==output==
        integer -- n raised to its own power.

        ==examples==
        >>>oeis_core.A000312(2)
        4
        >>>oeis_core.A000312(4)
        256
        >>>oeis_core.A000312(0)
        1

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n <0:
                raise ValueError('non-positive argument '+str(n))
        return n**n

def A000364(n):
        """ The n-th secant number.
        Essentially the taylor coefficient [x^(2n)] sec(x) multiplied by (2n)!.

        ==input==
        n -- integer >=0.

        ==output==
        integer -- the n-th value in [1,1,5,61,1385,...]

        ==examples==
        >>>oeis_core.A000364(2)
        3
        >>>oeis_core.A000396(4)
        1385
        >>>oeis_core.A000396(14)
        1252259641403629865468285

        ==author==
        Richard J. Mathar 2010-07-17
        """
        return A000364_list(n+1)[-1]
def A000364_list(n):
        """ The list of the first n secant numbers.
        The numerators of the coefficients of sec(x) = 1+x**2/2+5*x**4/24+..

        ==input==
        n -- integer >=0.

        ==output==
        integer -- the first n values in [1,1,5,61,1385,...]

        ==examples==
        >>>oeis_core.A000364_list(4)
        [1, 1, 5, 61]

        ==author==
        Richard J. Mathar 2010-07-17
        """
        a = [1,1,5]
        while len(a) < n:
                anew = 0
                nl = len(a)
                for i in range(nl):
                        anew -= (-1)**(i+nl)*a[i]* combinatorial.binomial(2*nl,2*i)
                a.append(anew)
        return a[0:n]

def A000396(n):
        """ The n-th perfect power.

        ==input==
        n -- integer between 0 and 14 (inclusive).

        ==output==
        integer -- n-th perfect power, starting 6, 28, 496,..

        ==examples==
        >>>oeis_core.A000396(2)
        28
        >>>oeis_core.A000396(4)
        8128

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return A000396_list(n)[-1]
def A000396_list(n):
        """ A list of the smallest perfect powers.
        This is not computed but simply taken from a static lookup table.

        ==input==
        n -- integer >0 .

        ==output==
        list -- the first n perfect numbers in [2 6, 28 ,496,..]

        ==examples==
        >>>oeis_core.A000396_list(6)
        [6, 28, 496, 8128, 33550336, 8589869056]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        a = [1, 6, 28, 496, 8128, 33550336, 8589869056, 137438691328, 2305843008139952128,
2658455991569831744654692615953842176,
191561942608236107294793378084303638130997321548169216,
13164036458569648337239753460458722910223472318386943117783728128,
14474011154664524427946373126085988481573677491474835889066354349131199152128,
23562723457267347065789548996709904988477547858392600710143027597506337283178622239730365539602600561360255566462503270175052892578043215543382498428777152427010394496918664028644534128033831439790236838624033171435922356643219703101720713163527487298747400647801939587165936401087419375649057918549492160555646976,
141053783706712069063207958086063189881486743514715667838838675999954867742652380114104193329037690251561950568709829327164087724366370087116731268159313652487450652439805877296207297446723295166658228846926807786652870188920867879451478364569313922060370695064736073572378695176473055266826253284886383715072974324463835300053138429460296575143368065570759537328128 ]
        if n <= len(a):
                return a[0:n]
        else:
                raise LookupError('Requested '+str(n)+' outsided tabulated range')

def isA000578(n):
        """ Test the argument for being a positive perfect third power.

        ==input==
        n -- integer >=0

        ==output==
        boolean -- True if the argument is >=0 and a perfect third power.

        ==examples==
        >>>oeis_core.isA000578(3)
        False
        >>>oeis_core.isA000578(8)
        True
        >>>oeis_core.isA000578(-8)
        False

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n < 0:
                return False
        if n < 2:
                return True
        f = factor.misc.FactoredInteger(n)
        for e in f.factors.values():
                if ( e %3 ) != 0:
                        return False
        return True
def A000593(n):
        """ The sum of the odd divisors of the argument.

        ==input==
        n -- integer >=0.

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A000593(6)
        4
        >>>oeis_core.A000593(75)
        124

        ==author==
        Richard J. Mathar 2010-07-03
        """
        a = 0
        for d in factor.misc.allDivisors(n):
                if (d &1) != 0:
                        a += d
        return a

def A000593_list(n):
        """ The list of the odd divisors of 1 to n.

        ==input==
        n -- integer >=0.

        ==output==
        list -- The truncated list starting [1, 1, 4, 1, 6, 4, 8, 1, 13, 6, 12, 4, ..]

        ==examples==
        >>>oeis_core.A000593_list(6)
        [1, 1, 4, 1, 6, 4]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return [A000593(i) for i in range(1,n+1)]

def A000720(n):
        """ PrimePi, the number of primes less than or equal to the argument.
        This function returns the PrimePi(n).

        ==input==
        n -- integer

        ==output==
        integer -- pi(n)

        ==examples==
        >>>oeis_core.A000720(1)
        0

        >>>oeis_core.A000720(5)
        3

        ==author==
        Richard J. Mathar 2010-07-01
        """
        a = 0
        p = 2
        while p <= n:
                p = prime.nextPrime(p)
                a += 1
        return a
def A000720_list(n):
        """ List of PrimePi(.) up to small arguments.
        This function returns the first n values of PrimePi(.), starting with 0.

        ==input==
        n -- integer

        ==output==
        list -- containing 0, 1, 2, 2, 3, 3,... with n values.

        >>>oeis_core.A000720_list(10)
        [0, 1, 2, 2, 3, 3, 4, 4, 4, 4]

        ==author==
        Richard J. Mathar 2010-07-01
        """
        a = []
        c = 0
        for i in range(1,n+1):
                if prime.primeq(i):
                        c += 1
                a.append(c)
        return a

def A000961(n):
        """ The n-th prime power.
        This function returns numbers of the form prime**e, e an integer >=0.
        For argument n=1, the 1 is returned.

        ==input==
        n -- integer >1

        ==output==
        integer -- the n-th number of the prime**e format.

        ==examples==
        >>>oeis_core.A000961(1)
        1
        >>>oeis_core.A000961(2)
        2
        >>>oeis_core.A000961(18)
        31

        ==author==
        Richard J. Mathar 2010-07-02
        """
        if n <=0:
                raise ValueError('non-positive argument '+str(n))
        i = 0
        c = 0
        while i < n:
                c += 1
                while not isA000961(c):
                        c += 1
                i += 1
        return c

def A000961_list(n):
        """ The first n numbers which are prime powers.
        This function returns a list of numbers of the form prime**e,
        e an integer >=0, starting at 1.

        ==input==
        n -- integer >0

        ==output==
        list -- The truncated list of [1, 2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17...]

        ==examples==
        >>>oeis_core.A000961_list(1)
        [1]
        >>>oeis_core.A000961_list(2)
        [1,2]
        >>>oeis_core.A000961_list(9)
        [1, 2, 3, 4, 5, 7, 8, 9, 11]

        ==author==
        Richard J. Mathar 2010-07-02
        """
        a = []
        c = 0
        while len(a)<n:
                c += 1
                while not isA000961(c):
                        c += 1
                a.append(c)
        return a

def isA000961(n):
        """ Test n against being a prime power.
        This function returns True if n is of the form prime**e, e an
        integer >=0.

        ==input==
        n -- integer >0

        ==output==
        boolen -- True if the argument is a prime power.

        ==examples==
        >>>oeis_core.isA000961(1)
        True
        >>>oeis_core.isA000961(2)
        True
        >>>oeis_core.isA000961(3)
        True
        >>>oeis_core.isA000961(4)
        True
        >>>oeis_core.isA000961(6)
        False

        ==author==
        Richard
        J. Mathar 2010-07-02
        """
        if n ==1:
                return True
        elif n <1:
                return False
        f = factor.misc.FactoredInteger(n)
        return (len(f.factors.values()) ==1 )

def A000984(n):
        """ The central binomial coefficient.
        This function returns the binomial(2*n,n)

        ==input==
        n -- integer >=0

        ==output==
        integer -- C(2n,n)

        ==examples==
        >>>oeis_core.A000984(1)
        2
        >>>oeis_core.A000984(5)
        252

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return combinatorial.binomial(2*n,n)

def A001003(n):
        """ Little Schroeder numbers.
        This function returns the n-th Little Schroeder number

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- The n-th element of [1,1,3,11,45,197,....]

        ==examples==
        >>>oeis_core.A001003(0)
        1
        >>>oeis_core.A001003(1)
        1
        >>>oeis_core.A001003(4)
        11
        >>>oeis_core.A001003(13)
        71039373

        ==author==
        Richard J. Mathar 2010-07-17
        """
        a = [1,1,3]
        if n <= 2:
                return a[n]
        for i in range(3,n+1):
                a[0:1] = []
                a.append( ((6*i-3)*a[1]-(i-2)*a[0])//(i+1) )
        return a[2]

def A001003_list(n):
        """ The list of the first n Little Schroeder Numbers

        ==input==
        n -- integer >=0.

        ==output==
        list -- The truncated list starting [1, 1, 3, 11, 45, ...]

        ==examples==
        >>>oeis_core.A001003_list(6)
        [1, 1, 3, 11, 45, 197]

        ==author==
        Richard J. Mathar 2010-07-17
        """
        a = [1,1,3]
        while len(a)< n:
                i = len(a)
                a.append( ((6*i-3)*a[-1]-(i-2)*a[-2])//(i+1) )
        return a[0:n]
def A001006(n):
        """ Motzkin numbers.
        This function returns the n-th Motzkin number

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- The n-th element of [1,1,2,4,9,21,....]

        ==examples==
        >>>oeis_core.A001006(0)
        1
        >>>oeis_core.A001006(1)
        1
        >>>oeis_core.A001006(4)
        9
        >>>oeis_core.A001006(29)
        593742784858

        ==author==
        Richard J. Mathar 2010-07-03
        """
        a = 0
        for k in range(n+1):
                a += (-1)**(n-k)*combinatorial.binomial(n,k)*A000108(k+1)
        return a

def A001006_list(n):
        """ List of the first Motzkin numbers.
        This function returns the list of the first n Motzkin numbers.

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- The truncated variant of [1,1,2,4,9,21,....]

        ==examples==
        >>>oeis_core.A001006_list(5)
        [1, 1, 2, 4, 9]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        a = [1,1,2]
        if n <= 3:
                return a[0:n]
        while len(a)< n:
                nexta = a[-1]
                i = len(a)
                for k in range(i-1):
                        nexta += a[k]*a[i-2-k]
                a.append(nexta)
        return a
def A001045(n):
        """ Jacobsthal numbers.
        This function returns J(n), n-th Jacobsthal number

        ==input==
        n -- integer >=0 .

        ==output== 
        integer -- J(n)

        ==examples==
        >>>oeis_core.A001045(0)
        0
        >>>oeis_core.A001045(1)
        1
        >>>oeis_core.A001045(2)
        1
        >>>oeis_core.A001045(3)
        3

        ==author== 
        Richard J. Mathar 2010-07-01
        """
        J = [0,1,1]
        if n <= 2:
                return J[n]
        for i in range(3,n+1):
                J[0:1] = []
                J.append(J[1]+2*J[0])
        return J[-1]

def A001045_list(n):
        """ list of omega(n)
        This function returns a list of the first omega(.)

        ==input==
        n -- integer >0 .

        ==output==
        list -- omega(1) up to omega(n)

        ==examples==
        >>>oeis_core.A001045_list(10)
        [0, 1, 1, 3, 5, 11, 21, 43, 85, 171]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        a = [0,1]
        if n <= 2:
                return a[0:n]
        while len(a) < n:
                a.append(a[-1]+2*a[-2])
        return a
def isA001045(n):
        """ Test the argument for being a Jacobstahl number.
        This function True or False depending on n being in A001045.

        ==input==
        n -- integer >=0 .

        ==output==
        boolean -- False for negative numbers, True for one of 0, 1, 3, 5, 11, 21 etc

        ==examples==
        >>>oeis_core.isA001045(0)
        True
        >>>oeis_core.isA001045(1)
        True
        >>>oeis_core.isA001045(2)
        False
        >>>oeis_core.isA001045(3)
        True

        ==author==
        Richard J. Mathar 2010-07-01
        """
        if n < 0:
                return False
        if n < 2:
                return True
        J = [0,1,1]
        while J[2] < n:
                J[0:1] = []
                J.append(J[1]+2*J[0])
        return (J[2] ==n)

def A001060(n):
        """ Thue-Morse(n).

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- 1 if the number of 1's in the binary representation of n
        is odd, 0 if it is even.

        ==examples==
        >>>oeis_core.A001045(0)
        0
        >>>oeis_core.A001045(1)
        1
        >>>oeis_core.A001045(2)
        1
        >>>oeis_core.A001045(3)
        0

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return (A000120(n) & 1)

def A001060_list(n):
        """ The first n values of the Thue-Mores sequence.

        ==input==
        n -- integer >=0 .

        ==output==
        list -- The first n values of [ 0, 1, 1, 0, 1, 0, 0, 1, 1, 0,..]

        ==examples==
        >>>oeis_core.A001060_list(10)
        [0, 1, 1, 0, 1, 0, 0, 1, 1, 0]

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return [A001060(i) for i in range(n)]

def A001147(n):
        """ Odd double factorial numbers.
        This function returns (2n-1)!!, the n-th odd double factorial.

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- (2n-1)!!, defined as 1 for n=0.

        ==examples==
        >>>oeis_core.A001147(0)
        1
        >>>oeis_core.A001147(1)
        1
        >>>oeis_core.A001147(2)
        3
        >>>oeis_core.A001147(4)
        105

        ==author==
        Richard J. Mathar 2010-07-02
        """
        if n <0:
                raise ValueError('negative argument '+str(n))
        a = 1
        for m in range(3,2*n,2):
                a *= m
        return a

def A001147_list(n):
        """ List of odd double factorial numbers.

        ==input==
        n -- integer >0 .

        ==output==
        list -- with n values starting [1,1,3,15,105,945,...]

        ==examples==
        >>>oeis_core.A001147_list(4)
        [1, 1, 3, 15]

        ==author==
        Richard J. Mathar 2010-07-02
        """
        a = []
        if n >0:
                a = [1]
                m = 1
                d = 1
                while len(a) < n:
                        a.append(d)
                        m += 1
                        d *= 2*m-1
        return a
def A001157(n):
        """ sigma_2(n)
        This function returns the sigma_2(n), the sum of the squares
        of the divisors of n.

        ==input==
        n -- positive integer

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A001157(6)
        50

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return multiplicative.sigma(2,n)

def A001157_list(n):
        """ sigma(n)
        This function returns the a list of the first sigma_2(n).

        ==input==
        n -- positive integer

        ==output==
        list -- The truncated list of [[1, 5, 10, 21, 26, 50,..]

        ==examples==
        >>>oeis_core.A001157_list(4)
        [1, 5, 10, 21]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return [A001157(i) for i in range(1,n+1)]

def A001221(n):
        """ omega(n)
        This function returns omega(n), the number of distinct prime factors of n

        ==input==
        n -- integer >0 .

        ==output==
        integer -- omega(n)

        ==examples==
        >>>oeis_core.A001221(0)
        0

        >>>oeis_core.A001221(1)
        0

        >>>oeis_core.A001221(30)
        3

        ==author==
        Richard J. Mathar 2010-06-29
        """
        f = factor.misc.FactoredInteger(n)
        return len(f.prime_divisors())

def A001221_list(n):
        """ list of omega(n)
        This function returns a list of the first omega(.)

        ==input==
        n -- integer >0 .

        ==output==
        list -- omega(1) up to omega(n)

        ==examples==
        >>>oeis_core.A001221_list(10)
        [0, 1, 1, 1, 1, 2, 1, 1, 1, 2]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return [A001221(i) for i in range(1,n+1)]

def A001222(n):
        """ big-omega(n)
        This function returns big-omega(n), the number of prime factors of n counted with multiplicity

        ==input==
        n -- integer >0 .

        ==output==
        integer -- Omega(n)

        ==examples==
        >>>oeis_core.A001222(1)
        0
        >>>oeis_core.A001222(32)
        5

        ==author==
        Richard J. Mathar 2010-06-29
        """
        f = factor.misc.FactoredInteger(n)
        a = 0
        for e in f.factors.values():
                a += e
        return a

def A001222_list(n):
        """ List of the first n values of big-omega(.)

        ==input==
        n -- integer >0 .

        ==output==
        list -- The list of [0, 1, 1, 2, 1, 2, 1, 3..] truncated to n terms.

        ==examples==
        >>>oeis_core.A001222_list(10)
        [0, 1, 1, 2, 1, 2, 1, 3, 2, 2]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return [A001222(i) for i in range(1,n+1)]
def A001333(n):
        """ Numerators of the continued fraction convergents to sqrt(2).
        The n-th number in the list of a(0)=a(1) and a(n)=2*a(n-1)+a(n-2).

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- The n-th term in [1, 1, 3, 7, 17, 41, 99, 239, 577, 1393..]

        ==examples==
        >>>oeis_core.A001333(0)
        1
        >>>oeis_core.A001333(1)
        1
        >>>oeis_core.A001333(2)
        3
        >>>oeis_core.A001333(6)
        99

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return oeis_trans.linRec([1,1],[2,1],n)

def A001333_list(n):
        """ List of the numerators of the continued fraction approximants to sqrt(2).

        ==input==
        n -- integer >0 .

        ==output==
        list -- The list of [1, 1, 3, 7, 17, 41, 99,..] truncated to n terms.

        ==examples==
        >>>oeis_core.A001333_list(10)
        [1, 1, 3, 7, 17, 41, 99, 239, 577, 1393]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return oeis_trans.linRec_list([1,1],[2,1],n)

def isA001358(n):
        """ Test for being a semiprime
        Returns True if the argument is a semiprime, else False

        ==input==
        n -- integer >= 0 .

        ==output==
        boolean -- True if the argument is a semiprime, else false.

        ==examples==
        >>>oeis_core.isA001358(10)
        True

        >>>oeis_core.isA001358(11)
        False

        ==author==
        Richard J. Mathar 2010-07-01
        """
        if n < 4:
                return False
        else:
                return ( A001222(n) == 2 )

def A001358(n):
        """ semiprime(n)
        This function returns semprime(n), the n-th number which is a product of two primes

        ==input==
        n -- integer >0 .

        ==output==
        integer -- semiprime(n)

        ==examples==
        >>>oeis_core.A001358(1)
        4

        >>>oeis_core.A001358(3)
        9

        ==author==
        Richard J. Mathar 2010-07-01
        """
        c = 0
        i = 3
        while c < n:
                i += 1
                while not isA001358(i):
                        i += 1
                c += 1
        return i


def A001358_list(n):
        """ list of low-indexed semiprimes
        This function returns a list of the first semiprime(.)

        ==input==
        n -- integer >0 .

        ==output==
        list -- semiprime(1) up to semiprime(n)

        ==examples==
        >>>oeis_core.A001358_list(10)
        [4, 6, 9, 10, 14, 15, 21, 22, 25, 26]

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return [A001358(i) for i in range(1,n+1)]

def A001405(n):
        """ The central binomial coefficient.
        This function returns binomial(n,floor(n/2)).

        ==input==
        n -- integer >=0

        ==output==
        integer -- C(n,[n/2])

        ==examples==
        >>>oeis_core.A001405(1)
        1
        >>>oeis_core.A001405(5)
        10

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return combinatorial.binomial(n,n//2)

def A001477(n):
        """ n .
        Note that there are easier ways to return the argument than
        calling this function :-)

        ==input==
        n -- integer

        ==output==
        integer -- n

        ==examples==
        >>>oeis_core.A005843(0)
        0
        >>>oeis_core.A005843(998)
        998

        ==author==
        Richard J. Mathar 2010-07-02
        """
        return n

def A001478(n):
        """ Copy of the negative of the argument.

        This function returns the argument multiplied by -1.

        ==input==
        n -- positive integer >0 .

        ==output==
        integer -- -n

        ==examples==
        >>>oeis_core.A001478(11)
        -11

        >>>oeis_core.A001478_list(10)
        [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]

        ==author==
        Richard J. Mathar 2010-09-06
        """
        return -n

def A001478_list(n):
        return [-i for i in range(1,n+1)]

def A001489(n):
        """ Copy of the negative of the argument.

        This function returns the argument multiplied by -1.

        ==input==
        n -- positive integer >=0 .

        ==output==
        integer -- -n

        ==examples==
        >>>oeis_core.A001489(11)
        -11

        >>>oeis_core.A001489_list(10)
        [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]

        ==author==
        Richard J. Mathar 2010-09-06
        """
        return -n

def A001489_list(n):
        return [-i for i in range(0,n)]

def A001519(n):
        """ The n-th term in a recurrence a(n)=3a(n-1)-a(n-2).
        Initialized with return values of 1 for 0<=n<=1.

        ==input==
        n -- integer >=0.

        ==output==
        integer -- a(n).

        ==examples==
        >>>oeis_core.A001519(0)
        1
        >>>oeis_core.A001519(1)
        1
        >>>oeis_core.A001519(4)
        13

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return oeis_trans.linRec([1,1],[3,-1],n)

def A001519_list(n):
        """ The first n terms of the recurrence a(n)=3a(n-1)-a(n-2).
        The first two elements are defined as 1.

        ==input==
        n -- integer >=0.

        ==output==
        list -- The first n elements of [1, 1, 2, 5, 13, 34, 89, 233,..]

        ==examples==
        >>>oeis_core.A001519(10)
        [1, 1, 2, 5, 13, 34, 89, 233, 610, 1597]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return oeis_trans.linRec_list([1,1],[3,-1],n)

def A001699(n):
        """ Number of binary trees of height n.

        ==input==
        n -- integer >= 0

        ==output==
        integer -- The n-th element of [1, 1, 3, 21, 651, 457653,...]

        ==examples==
        >>>oeis_core.A001699(0)
        1
        >>>oeis_core.A001699(2)
        3
        >>>oeis_core.A001699(3)
        21

        ==author==
        Richard J. Mathar 2010-09-06
        """
        if n <0:
                raise ValueError('negative argument '+str(n))
        return A001699_list(n+1)[-1]

def A001699_list(n):
        """ Recursively a(n+1) = 2*a(n)*sum_{i=0..n-1}a(i) + a(n)^2.

        ==input==
        n -- integer >= 0

        ==output==
        list -- The first n elements of [1, 1, 3, 21, 651, 457653,...]

        ==examples==
        >>>oeis_core.A001699_list(3)
        [1, 1, 3]

        ==author==
        Richard J. Mathar 2010-09-06
        """
        a = [1,1]
        while len(a) < n:
                i = len(a)
                s = 0
                for j in range(i-1):
                        s += a[j]
                s *= 2*a[-1]
                s += a[-1]**2
                a.append(s)
        return a[0:n]

def A001700(n):
        """ Ballot number binomial(2n+1,n+1).

        ==input==
        n -- integer

        ==output==
        integer -- C(2n+1,n+1).

        ==examples==
        >>>oeis_core.A001700(0)
        1
        >>>oeis_core.A001700(1)
        3
        >>>oeis_core.A001700(2)
        10

        ==author==
        Richard J. Mathar 2010-07-02
        """
        if n <0:
                return 0
        else:
                return combinatorial.binomial(2*n+1,n+1)

def A001700_list(n):
        """
        Richard J. Mathar 2010-07-02
        """
        return [A001700(i) for i in range(n)]

def A001764(n):
        """ binomial(3n,n)/(2n+1).
        Pfaff-Fuss-Catalan number C^3(n).

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- C(3n,n)/(2n+1).

        ==examples==
        >>>oeis_core.A001764(0)
        1
        >>>oeis_core.A001764(1)
        1
        >>>oeis_core.A001764(13)
        300830572

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n <0:
                return 0
        return combinatorial.binomial(3*n,n)//(2*n+1)

def A001764_list(n):
        """ List of odd double factorial numbers.

        ==input==
        n -- integer >0 .

        ==output==
        list -- with n values starting [1,1,3,15,105,945,...]

        ==examples==
        >>>oeis_core.A001764_list(4)
        [1, 1, 3, 15]

        ==author==
        Richard J. Mathar 2010-07-02
        """
        a = []
        if n >0:
                a = [1]
                m = 1
                d = 1
                while len(a) < n:
                        a.append(d)
                        m += 1
                        d *= 2*m-1
        return a
def A001906(n):
        """ Fibonacci number at index 2n.
        This function returns the Fibonacci(2n).

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- Fibonacci(2*n)

        ==examples==
        >>>oeis_core.A001906(0)
        0
        >>>oeis_core.A001906(1)
        1
        >>>oeis_core.A001906(2)
        3
        >>>oeis_core.A001906(3)
        8
        >>>oeis_core.A001906(20)
        102334155

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n <0:
                raise ValueError('negative argument '+str(n))
        return oeis_trans.linRec([0,1],[3,-1],n)

def A001906_list(n):
        """ List of the small Fibonacci numbers.
        This function returns the truncated list of the bisected Fibonacci numbers 0 ,1 ,3, 8, 21,..

        ==input==
        n -- integer >=0 .

        ==output==
        list -- The first n values of [0,1,1,2,3,...]

        ==examples==
        >>>oeis_core.A001906_list(10)
        [0, 1, 3, 8, 21, 55, 144, 377, 987, 2584]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return oeis_trans.linRec_list([0,1],[3,-1],n)

def A002106(n):
        """ Number of transitive permutation groups of degree n.
        This is not computed but simply taken from a static lookup table.

        ==input==
        n -- integer >0 .

        ==output==
        integer -- The count of groups, including the primitive groups.

        ==examples==
        >>>oeis_core.A002106(3)
        2
        >>>oeis_core.A002106(6)
        16

        ==author==
        Richard J. Mathar 2010-09-06
        """
        return A002106_list(n)[-1]
def A002106_list(n):
        """ Count of transitive permutation groups for degree >=1.
        This is not computed but simply taken from a static lookup table.

        ==input==
        n -- integer >0 .

        ==output==
        list -- the first n number of groups [1,1,2,5,5,..]

        ==examples==
        >>>oeis_core.A002106_list(10)
        [1, 1, 2, 5, 5, 16, 7, 50, 34, 45]

        ==author==
        Richard J. Mathar 2010-09-06
        """
        a = [1, 1, 2, 5, 5, 16, 7, 50, 34, 45, 8, 301, 9, 63, 104, 1954, 10, 983,
                8, 1117, 164, 59, 7, 25000, 211, 96, 2392, 1854, 8, 5712, 12]
        if n <= len(a):
                return a[0:n]
        else:
                raise LookupError('Requested '+str(n)+' outsided tabulated range')

def A002110(n):
        """ Primorial(n)
        This function returns the n-th primorial

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- p#

        ==examples==
        >>>oeis_core.A002110(3)
        30

        ==author==
        Richard J. Mathar 2010-06-29
        """
        a =  1
        for i in range(1,n+1):
                a *= prime.prime(i)
        return a

def A002110_list(n):
        """ List of the first Primorials.
        This function returns the first n primorials

        ==input==
        n -- integer >=0 .

        ==output==
        list -- the first n primorials starting with 1.

        ==examples==
        >>>oeis_core.A002110_list(3)
        [1, 2, 6]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return [A002110(i) for i in range(n)]

def isA002113(n):
        """ Test whether the argument is a palindrome in base 10.

        ==input==
        n -- integer >=0 .

        ==output==
        boolean -- True if the decimal representation is the same read forwards or backwards.

        ==examples==
        >>>oeis_core.isA002113(3)
        True
        >>>oeis_core.isA002113(303)
        True
        >>>oeis_core.isA002113(302)
        False

        ==author==
        Richard J. Mathar 2010-07-03
        """
        p = baseCoeff(n)
        l = len(p)
        for i in range( l//2):
                if p[i] != p[l-i-1]:
                        return False
        return True

def A002113_list(n):
        """ Return a list of the first palidromes in base 10.

        ==input==
        n -- integer >=0 .

        ==output==
        list -- the truncated list of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66,..]

        ==examples==
        >>>oeis_core.A002113_list(10)
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        a = []
        c = -1
        while len(a)< n:
                c += 1
                while not isA002113(c):
                        c += 1
                a.append(c)
        return a

def A002113(n):
        """ Return the n-th palindrome in base 10.

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- the n-th number (starting with 0) which is its own digit-reversed variant.

        ==examples==
        >>>oeis_core.A002113(1)
        0
        >>>oeis_core.A002113(20)
        101

        ==author==
        Richard J. Mathar 2010-07-03
        """
        i = 0
        c = -1
        while i< n:
                c += 1
                while not isA002113(c):
                        c += 1
                i += 1
        return c

def A002275(n):
        """ Repunit(n)

        R_n, the number with decimal representation 1111....11

        ==input==
        n -- integer >=0 .

        ==output==
        integer -- the number containing n ones.

        ==examples==
        >>>oeis_core.A002275(5)
        11111

        ==author==
        Richard J. Mathar 2010-06-29
        """
        if n <=0:
                return 0
        else:
                return (10**n-1)//9

def A002275_list(n):
        """ List of repunit(n)

        ==input==
        n -- integer >=0 .

        ==output==
        list -- the first n repunits, 0, 1, 11, ..., R(n-1)

        ==examples==
        >>>oeis_core.A002275_list(4)
        [0, 1, 11, 111]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return [A002275(i) for i in range(n)]

def isA002275(n):
        """ Test the argument for being a Repunit

        ==input==
        n -- integer >=0 .

        ==output==
        boolean -- True if the argument is 0 or of the form 1111...111 else False

        ==examples==
        >>>oeis_core.isA002275(111)
        True

        >>>oeis_core.isA002275(1110)
        False

        ==author==
        Richard J. Mathar 2010-07-01
        """
        if n <0:
                return False
        elif n ==0:
                return True
        else:
                nshft = n
                while nshft > 0:
                        if ( nshft % 10 ) != 1:
                                return False
                        nshft //= 10
                return True

def A002378(n):
        """ Oblong number.
        This function returns n*(n+1).

        ==input==
        n -- integer

        ==output==
        integer -- n*(n+1)

        ==examples==
        >>>oeis_core.A002378(0)
        0
        >>>oeis_core.A002378(1)
        2
        >>>oeis_core.A002378(3)
        12

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return n*(n+1)

def A002378_list(n):
        """ List of the first n Oblong Numbers.

        ==input==
        n -- integer >=0 .

        ==output==
        list -- n items starting [0, 2, 6, 12,..]

        ==examples==
        >>>oeis_core.A002378_list(10)
        [0, 2, 6, 12, 20, 30, 42, 56, 72, 90]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return [i*(i+1) for i in range(n)]
def isA002378(n):
        """ Test for being a number of the form k*(k+1).
        This function tests whether the argument is an Oblong Number.

        ==input==
        n -- integer >=1 .

        ==output==
        boolen -- False if the argument is not of the form k*(k+1), k>=0.

        ==examples==
        >>>oeis_core.isA002378(3)
        False

        >>>oeis_core.isA002378(6)
        True

        >>>oeis_core.isA002378(120)
        False

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n < 0:
                return False
        if arith1.issquare(1+4*n) ==0:
                return False
        else:
                return True

def A002426(n):
        """ n-th Trinomial Coefficient.
        The largest coefficient in the expansion of (1+x+x^2)^n.

        ==input==
        n -- integer

        ==output==
        integer --

        ==examples==
        >>>oeis_core.A002426(0)
        1
        >>>oeis_core.A002426(1)
        1
        >>>oeis_core.A002426(4)
        19

        ==author==
        Richard J. Mathar 2010-07-03
        """
        a=0
        for k in range(n+1):
                # a += combinatorial.binomial(n,k)*combinatorial.binomial(k,n-k)
                if 2*k >= n:
                        a += combinatorial.binomial(n,k)*combinatorial.binomial(k,n-k)
        return a

def A002531(n):
        """ nth numerator of continued fraction convergents to sqrt(3).

        ==input==
        n -- integer >=0 .

        ==output==
        integer --

        ==examples==
        >>>oeis_core.A002531(0)
        1
        >>>oeis_core.A002531(1)
        1
        >>>oeis_core.A002531(2)
        2
        >>>oeis_core.A002531(3)
        5
        >>>oeis_core.A002531(20)
        262087

        ==author==
        Richard J. Mathar 2010-09-06
        """
        if n <0:
                raise ValueError('negative argument '+str(n))
        return oeis_trans.linRec([1,1,2,5],[0,4,0,-1],n)

def A002531_list(n):
        """ n numerators of continued fraction convergents to sqrt(3).

        ==input==
        n -- integer >=0 .

        ==output==
        list -- starting [1,1,2,5,7,19..]

        ==examples==
        >>>oeis_core.A002531_list(3)
        [1, 1, 2]

        ==author==
        Richard J. Mathar 2010-09-06
        """
        if n <0:
                raise ValueError('negative argument '+str(n))
        return oeis_trans.linRec_list([1,1,2,5],[0,4,0,-1],n)

def A002620(n):
        """ floor(n^2/4).

        ==input==
        n -- integer

        ==output==
        integer -- n^2/4 rounded to zero.

        ==examples==
        >>>oeis_core.A002620(0)
        0
        >>>oeis_core.A002620(1)
        0
        >>>oeis_core.A002620(3)
        2

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return (n**2)//4

def A002620_list(n):
        """ The values floor(k^2/4) starting at k=0.

        ==input==
        n -- integer

        ==output==
        list -- The first n elements of [0, 0, 1, 2, 4, 6, 9, 12, 16, 20..]

        ==examples==
        >>>oeis_core.A002620_list(10)
        [0, 0, 1, 2, 4, 6, 9, 12, 16, 20]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return [(i**2)//4 for i in range(n)]

def A002658(n):
        """ Recursively a(n+1) = a(n)*sum_{i=0..n-1}a(i)+ a(n)*(a(n)+1)/2.

        ==input==
        n -- integer >= 0

        ==output==
        list -- The a(n) elements of a(0)=a(1)=1, a(2)=2, a(3)=7...

        ==examples==
        >>>oeis_core.A002658(6)
        2595782

        ==author==
        Richard J. Mathar 2010-09-06
        """
        return A002658_list(n+1)[-1]

def A002658_list(n):
        """ Recursively a(n+1) = a(n)*sum_{i=0..n-1}a(i)+ a(n)*(a(n)+1)/2.

        ==input==
        n -- integer >= 0

        ==output==
        list -- The first n elements of [1, 1, 2, 7, 56,..]

        ==examples==
        >>>oeis_core.A002658_list(7)
        [1, 1, 2, 7, 56, 2212, 2595782]

        ==author==
        Richard J. Mathar 2010-09-06
        """
        a = [1,1,2]
        while len(a) < n:
                i = len(a)
                s = 0
                for j in range(i-1):
                        s += a[j]
                s *= a[-1]
                s += a[-1]*(1+a[-1])//2
                a.append(s)
        return a[0:n]

def A002808(n):
        """ The n-th composite number.
        This function returns the n-th composite number, starting with 4.

        ==input==
        n -- integer >=1 .

        ==output==
        integer -- composite(n)

        ==examples==
        >>>oeis_core.A002808(1)
        4
        >>>oeis_core.A002808(2)
        6
        >>>oeis_core.A002808(3)
        8

        ==author==
        Richard J. Mathar 2010-07-01
        """
        c = 3
        i = 0
        while i < n:
                c += 1
                while prime.primeq(c):
                        c += 1
                i += 1
        return c

def A002808_list(n):
        """ The first n composite numbers.
        This function returns a list of the first n composite numbers, starting with 4.

        ==input==
        n -- integer >=1 .

        ==output==
        list -- Containing n elements, starting with 4, 6,8 ,9, 10.

        ==examples==
        >>>oeis_core.A002808_list(0)
        []
        >>>oeis_core.A002808_list(10)
        [4, 6, 8, 9, 10, 12, 14, 15, 16, 18

        ==author==
        Richard J. Mathar 2010-07-01
        """
        c = 3
        a = []
        while len(a) < n:
                while prime.primeq(c):
                        c += 1
                a.append(c)
                c += 1
        return a
def isA002808(n):
        """ Test the argument for compositeness.
        This function tests the number against being a member of the A002808
        sequence, so for all negative arguments and for all arguments <4 the
        result will be False, although numbers like -28= 4*(-7) are composite.

        ==input==
        n -- integer .

        ==output==
        True or False

        ==examples==
        >>>oeis_core.isA002808(-12)
        False
        >>>oeis_core.isA002808(-11)
        False
        >>>oeis_core.isA002808(0)
        False
        >>>oeis_core.isA002808(1)
        False
        >>>oeis_core.isA002808(3)
        False
        >>>oeis_core.isA002808(4)
        True
        >>>oeis_core.isA002808(888)
        True

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return ( n >= 4 and (not prime.primeq(n) ) )

def A003418(n):
        """ The least common multiple of the numbers 1 to n.

        ==input==
        n -- integer >=0.

        ==output==
        integer -- 1 if n =0, else lcm(1,2,3,4,....n)

        ==examples==
        >>>oeis_core.A003418(12)
        27720

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n < 0:
                raise ValueError('non-positive argument '+str(n))
        a = 1
        for i in range(2,n+1):
                a = gcd.lcm(a,i)
        return a

def A003484(n):
        """ Radon function.

        ==input==
        n -- integer >0.

        ==output==
        integer -- If n = 2**(4*b+c)*d with d odd, then the value is 8*b+2**c

        ==examples==
        >>>oeis_core.A003484(1)
        1
        >>>oeis_core.A003484(2)
        2
        >>>oeis_core.A003484(16)
        9

        ==author==
        Richard J. Mathar 2010-09-06
        """
        if n <= 0:
                raise ValueError('non-positive argument '+str(n))
        p2 = A007814(n)
        b, c = divmod(p2,4)
        return 8*b + 2**c

def A004011(n):
        """ Theta series of the D_4 lattice.

        ==input==
        n -- integer >=0.

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A004011(4)
        24
        >>>oeis_core.A004011(5)
        144

        ==author==
        Richard J. Mathar 2010-09-06
        """
        if n < 0:
                raise ValueError('negative argument '+str(n))
        if n == 0:
                return 1
        else:
                return 24*A000593(n)

def A004011_list(n):
        """ The first n values of the theta series of the D_4 lattice.

        ==input==
        n -- integer >=0.

        ==output==
        list -- The first n values of [1, 24, 24, 96, 24, 144, 96,..]

        ==examples==
        >>>oeis_core.A004011_list(4)
        [1, 24, 24, 96]

        ==author==
        Richard J. Mathar 2010-09-06
        """
        if n < 0:
                raise ValueError('negative argument '+str(n))
        if n == 0:
                return []
        L = [1]
        if n == 1:
                return L
        else:
                L.extend([24*A000593(i) for i in range(1,n)])
                return L

def A004526(n):
        """ floor(n/2).

        ==input==
        n -- integer >=0.

        ==output==
        integer -- half of n, rounded down.

        ==examples==
        >>>oeis_core.A004526(11)
        5

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n < 0:
                raise ValueError('non-positive argument '+str(n))
        return n//2

def A004526_list(n):
        """
        ==examples==
        >>>oeis_core.A004526_list(11)
        [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        return [i//2 for i in range(n)]

def A005117(n):
        """ The n-th squarefree number, starting at 1.

        ==input==
        n -- integer > 0 .

        ==output==
        integer -- the n-th squarefree number. This equals n if 1<=n<=3.

        ==examples==
        >>>oeis_core.A005117(1)
        1
        >>>oeis_core.A005117(7)
        10

        ==author==
        Richard J. Mathar 2010-07-02
        """
        if n <=0:
                raise ValueError('non-positive argument '+str(n))
        c = 0
        i = 0
        while c< n:
                i += 1
                c += 1
                while not isA005117(i):
                        i += 1
        return i

def A005117_list(n):
        """ List of the first n squarefree numbers.
        Return the squarefree numbers [1, 2, 3, 5, 6, 7, 10, 11, 13, 14..].

        ==input==
        n -- integer > 0 .

        ==output==
        list -- of length n with the lowest squarefree numbers.

        ==examples==
        >>>oeis_core.isA005117_list(1)
        [1]
        >>>oeis_core.A005117_list(10)
        [1, 2, 3, 5, 6, 7, 10, 11, 13, 14]

        ==author==
        Richard J. Mathar 2010-07-02
        """
        a = []
        i = 0
        while len(a) < n:
                i += 1
                a.append(i)
                while not isA005117(i):
                        i += 1
        return a

def isA005117(n):
        """ Test for being squarefree.
        Returns True the argument is a squarefree number (product of distinct primes) >=1.

        ==input==
        n -- integer > 0 .

        ==output==
        boolean -- True if the argument is squarefree.

        ==examples==
        >>>oeis_core.isA005117(1)
        True
        >>>oeis_core.isA005117(10)
        True
        >>>oeis_core.isA005117(11)
        True
        >>>oeis_core.isA005117(12)
        False

        ==author==
        Richard J. Mathar 2010-07-02
        """
        if n < 1:
                return False
        else:
                f = factor.misc.FactoredInteger(n)
                for e in f.factors.values():
                        if e >1:
                                return False
                return True

def A005230(n):
        """ Stern's sequence: a(1)=1, otherwise the sum of the previous m
        terms, where m=ceil((sqrt(8*n+1)-1)/2) .

        ==input==
        n -- integer

        ==output==
        integer -- The n'th value in [1,1,2,3,6,11,20,40,77]

        ==examples==
        >>>oeis_core.A005230(1)
        1
        >>>oeis_core.A005230(14)
        2200

        ==author==
        Richard J. Mathar 2010-09-06
        """
        return A005230_list(n)[-1]

def A005230_list(n):
        """ The first n terms of Stern's sequence.

        ==input==
        n -- integer

        ==output==
        list -- The first n values of [1,1,2,3,6,11,20,40,77,..]

        ==examples==
        >>>oeis_core.A005230_list(1)
        [1]
        >>>oeis_core.A005230_list(14)
        [1, 1, 2, 3, 6, 11, 20, 40, 77, 148, 285, 570, 1120, 2200]

        ==author==
        Richard J. Mathar 2010-09-06
        """
        a = [1, 1, 2, 3]
        while len(a) < n:
                i = len(a)
                m = oeis_bulk.A002024(i)
                s = 0
                for j in range(1,m+1):
                        s += a[-j]
                a.append(s)
        return a[0:n]

def A005408(n):
        """ 2n+1 .

        ==input==
        n -- integer

        ==output==
        integer -- 2*n+1

        ==examples==
        >>>oeis_core.A005408(0)
        1
        >>>oeis_core.A005408(2)
        5

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return 2*n+1

def A005408_list(n):
        """ The first n odd numbers.
        This function returns a list of the first n odd numbers

        ==input==
        n -- integer >=1 .

        ==output==
        list -- Containing n elements, starting with 1,3,5,7,..

        ==examples==
        >>>oeis_core.A005408_list(0)
        []
        >>>oeis_core.A005408_list(3)
        [1, 3, 5]

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return [2*i+1 for i in range(n)]

def isA005408(n):
        """ Test the argument for being a positive odd number.

        ==input==
        n -- integer .

        ==output==
        boolean -- True or False

        ==examples==
        >>>oeis_core.isA005408(-11)
        False
        >>>oeis_core.isA005408(11)
        True
        >>>oeis_core.isA005408(10)
        False

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return ( n >= 1 and ( (n & 1) == 1) )

def A005843(n):
        """ 2n .
        Note that there are easier programs to multiply a number by 2 than
        calling this function :-)

        ==input==
        n -- integer

        ==output==
        integer -- 2*n

        ==examples==
        >>>oeis_core.A005843(0)
        0
        >>>oeis_core.A005843(2)
        4

        ==author==
        Richard J. Mathar 2010-07-02
        """
        return 2*n

def A005843_list(n):
        """ The first n even numbers.
        This function returns a list of the first n even numbers, starting at 0.

        ==input==
        n -- integer >=1 .

        ==output==
        list -- Containing n elements, starting with 0,2,4,6,..

        ==examples==
        >>>oeis_core.A005843_list(0)
        []
        >>>oeis_core.A005843_list(3)
        [0, 2, 4]

        ==author==
        Richard J. Mathar 2010-07-02
        """
        return [2*i for i in range(n)]

def A006530(n):
        """ The largest prime divisor.
        This function returns the largest prime dividing n.

        ==input==
        n -- integer >0

        ==output==
        integer -- the largest prime factor, or 1 if n==1.

        ==examples==
        >>>oeis_core.A006530(1)
        1
        >>>oeis_core.A006530(3)
        3
        >>>oeis_core.A006530(4)
        2

        ==author==
        Richard J. Mathar 2010-07-01
        """
        if n==1:
                return 1
        f = factor.misc.FactoredInteger(n)
        return max(f.prime_divisors())

def A006530_list(n):
        """ List of largest prime factors from 1 to n.

        ==input==
        n -- integer >=1 .

        ==output==
        list -- the first n elements of A006530.

        ==examples==
        >>>oeis_core.A006530_list(10)
        [1, 2, 3, 2, 5, 3, 7, 2, 3, 5]

        ==author==
        Richard J. Mathar 2010-07-01
        """
        return [A006530(i) for i in range(1,n+1)]

def A006894(n):
        """ Number of planted 3-trees of height <n.

        ==input==
        n -- integer > 0

        ==output==
        list -- Recursively a(n+1)= a(n)*(a(n)+1)/2, starting a(1)=1.

        ==examples==
        >>>oeis_core.A006894(1)
        1
        >>>oeis_core.A006894(2)
        2
        >>>oeis_core.A006894(3)
        4

        ==author==
        Richard J. Mathar 2010-09-06
        """
        if n <= 0:
                raise ValueError('non-positive argument '+str(n))
        a = 1
        for i in range(n-1):
                a = a*(1+a)//2
                a += 1
        return a

def A006894_list(n):
        """ Recursively a(n+1) = 1+a(n)*(a(n)+1)/2.

        ==input==
        n -- integer >= 0

        ==output==
        list -- The first n elements of [1, 2, 4, 11, 67..]

        ==examples==
        >>>oeis_core.A006894_list(7)
        [1, 2, 4, 11, 67, 2279, 2598061]

        ==author==
        Richard J. Mathar 2010-09-06
        """
        a = [1,2]
        while len(a) < n:
                s = 1+a[-1]*(1+a[-1])//2
                a.append(s)
        return a[0:n]

def A007318(n,k):
        """
        This function returns binomial(n,k) =C(n,k)

        ==input==
        n,k -- positive integers n>=0

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A007318(-3,4)
        ValueError: non-positive number: -3

        >>>oeis_core.A007318(4,2)
        6

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return combinatorial.binomial(n,k)

def A008275(n,k):
        """
        This function returns Stirling1(n,k)

        ==input==
        n,k -- positive integers n>=1

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A008275(-3,4)
        0

        >>>oeis_core.A008275(5,3)
        35

        >>>oeis_core.A008275(5,2)
        -50

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return combinatorial.stirling1(n,k)

def A008275_row(n):
        """ Row of stirling1(n,.) numbers.

        ==input==
        n -- positive integer n>=1

        ==output==
        list -- Stirling1(n,1) up to Stirling1(n,n)

        ==examples==
        >>>oeis_core.A008275_row(3)
        [2, -3, 1]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n <= 0:
                raise ValueError('non-positive argument '+str(n))
        return [A008275(n,k) for k in range(1,n+1)]

def A008277(n,k):
        """ Stirling number of the second kind.
        This function returns Stirling2(n,k)

        ==input==
        n,k -- positive integers n>=1

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A008277(-3,4)
        0

        >>>oeis_core.A008277(5,3)
        25

        >>>oeis_core.A008277(5,2)
        15

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return combinatorial.stirling2(n,k)

def A008292(n,k):
        """ Eulerian(n,k).
        This function returns the eulerian number in row n, column k.

        ==input==
        n,k -- positive integers n>=1, 1<=k<=n

        ==output==
        integer -- function value

        ==examples==
        >>> oeis_core.A008292(1,1)
        1
        >>> oeis_core.A008292(3,2)
        4


        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n < 1:
                return 0
        if k < 1 or k>n:
                return 0
        a = 0
        for j in range(k+1):
                a += (-1)**j * combinatorial.binomial(n+1,j)* ((k-j)**n)
        return a

def A008292_row(n):
        """ List of Eulerian(n,k) for 1<=k<=n.
        This function returns the eulerian number in row n.

        ==input==
        n -- integer n>=1.

        ==output==
        list -- the values Eulerian(n,.)

        ==examples==
        >>> oeis_core.A008292_row(3)
        [1, 4, 1]
        >>> oeis_core.A008292_row(10)
        [1, 1013, 47840, 455192, 1310354, 1310354, 455192, 47840, 1013, 1]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n < 1:
                raise ValueError('non-positive argument '+str(n))
        return [A008292(n,k) for k in range(1,n+1)]

def A008683(n):
        """
        This function returns mu(n), the Moebius function

        ==input==
        n -- positive integer

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A008683(11)
        -1

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return multiplicative.moebius(n)

def A008683_list(n):
        """
        This function returns the first n elements of the Moebius function

        ==input==
        n -- positive integer

        ==output==
        list -- elements mu(1) through mu(n)

        ==examples==
        >>>oeis_core.A008683_list(10)
        [1, -1, -1, 0, -1, 1, -1, 0, 0, 1]

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return [A008683(i) for i in range(1,n+1)]

def A018252(n):
        """ The n-th positive non-prime number.
        Starting with 1 and4 for argument n=1 and 2.

        ==input==
        n -- integer >0.

        ==output==
        integer -- The corresponding element of [1, 4, 6, 8, 9, 10, 12, 14, 15..]

        ==examples==
        >>>oeis_core.A018252(1)
        1
        >>>oeis_core.A018252(2)
        4
        >>>oeis_core.A018252(3)
        6

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n <= 0:
                raise ValueError('non-positive argument '+str(n))
        if n == 1:
                return 1
        return A002808(n-1)

def A027641(n):
        """
        This function returns the numerator of the Bernoulli number (n)

        ==input==
        n -- positive integer

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A027641(6)
        1

        >>>oeis_core.A027641(12)
        -691

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return combinatorial.bernoulli(n).numerator

def A027642(n):
        """
        This function returns the denominator of the Bernoulli number (n)

        ==input==
        n -- positive integer

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A027642(6)
        42

        ==author==
        Richard J. Mathar 2010-06-29
        """
        return combinatorial.bernoulli(n).denominator

def A049310(n,k):
        """ Coefficients of Chebyshev U(n,x/2) polynomial.
        This function returns the coefficient [x**k] S(n,x).

        ==input==
        n -- integer >=0
        k -- integer 0<=k<=n

        ==output==
        integer -- function value

        ==examples==
        >>>oeis_core.A049310(3,1)
        -2
        >>>oeis_core.A049310(7,3)
        10

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if k>n or k<0 or n<0:
                return 0
        if (n+k) %2 ==1:
                return 0
        nkhalf = (n+k)//2
        return (-1)**(nkhalf+k) * combinatorial.binomial(nkhalf,k)

def A049310_row(n):
        """ Coefficients of Chebyshev U(n,x/2) polynomial.
        This function returns the the cofficients of x**0, x**1 etc as a list

        ==input==
        n -- integer >=0

        ==output==
        list -- the n+1 integer coefficients of the polynomial

        ==examples==
        >>>oeis_core.A049310_row(3)
        [0, -2, 0, 1]
        >>>oeis_core.A049310_row(7)
        [0, -4, 0, 10, 0, -6, 0, 1]

        ==author==
        Richard J. Mathar 2010-07-03
        """
        if n<0:
                return []
        return [ A049310(n,k) for k in range(n+1)]