cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

User: Charles Paul

Charles Paul's wiki page.

Charles Paul has authored 3 sequences.

A354718 a(n) is the smallest number b such that n, written in base 10 and interpreted as a base-b number, is a prime (or -1 if no such base exists).

Original entry on oeis.org

-1, 3, 4, -1, 6, -1, 8, -1, -1, 2, 2, 3, 4, 7, 6, 7, 10, 9, 10, -1, 3, -1, 4, -1, 6, -1, 8, -1, 10, -1, 4, 5, -1, 5, 6, -1, 8, 11, -1, -1, 7, -1, 5, -1, 6, -1, 9, -1, 11, -1, 6, 7, 8, 11, -1, 7, 8, 9, 10, -1, 7, -1, -1, -1, 7, -1, 9, -1, -1, -1, 10, 11, 8, 9
Offset: 1

Author

Charles Paul, Jun 03 2022

Keywords

Comments

The minimum base considered is one greater than the greatest digit, i.e., max_digit(n) = d requires a base > d. E.g., a(17)=10, even though "base 4" 4*1 + 1*7 = 11 is prime.

Examples

			a(14) = 7, because 14_7 = 7*1 + 1*4 = 11, which is prime, but both 14_6 = 10 and 14_5 = 9 are nonprime (and the digit 4 requires a base b > 4).
a(101) = 2, because 2^2*1 + 2*0 + 1*1 = 5, which is prime.
a(24) = -1, because the digits 2 and 4 share GCD 2, so there is no base b in which 24_b is prime (because 24_b is divisible by 2 in any base b).
a(100) = -1, because in any base b, 100_b = b^2, which cannot be prime.
a(112) = -1, because for any base b, b^2 + b + 2 is even (i.e., divisible by 2).
		

Programs

  • Python
    # Self-explanatory
    def is_prime(n):
         return not (n < 2 or any(n % x == 0 for x in range(2, int(n ** 0.5) + 1)))
    # Evaluate an intish string in a given base
    def atoi_base(s, b):
        out = 0
        for i in range(len(s)):
            d = s[-1-i]
            out += (b**i)*int(d)
        return out
    # Constants
    NUM_TERMS = 200 # Number of terms to generate
    MAX_VALUE = 999 # Maximum base to consider before saying "no base will do this"
    NUL_RESULT = -1 # Value returned when no valid base can be found
    # Main func
    def a(n):
        assert(n > 0)
        # Start with 1 ... 9
        if n < 10:
            return n+1 if is_prime(n) else NUL_RESULT
        # Check all bases up to MAX_VALUE
        base = int(max(str(n))) + 1
        while True:
            if base >= MAX_VALUE:
                return NUL_RESULT
                break
            elif is_prime(atoi_base(str(n), base)):
                return base
                break
            else:
                base += 1
    for n in range(1, NUM_TERMS):
        print(a(n), end=', ')

A306252 Least primitive root mod A033948(n).

Original entry on oeis.org

0, 1, 2, 3, 2, 5, 3, 2, 3, 2, 2, 3, 3, 5, 2, 7, 5, 2, 7, 2, 2, 3, 3, 2, 3, 6, 3, 5, 5, 3, 3, 2, 5, 3, 2, 2, 3, 2, 7, 5, 5, 3, 2, 7, 2, 3, 3, 5, 5, 3, 2, 5, 3, 2, 6, 3, 11, 2, 7, 2, 3, 2, 7, 3, 2, 7, 5, 2, 6, 5, 3, 5, 2, 5, 5, 2, 2, 3, 2, 2, 19, 5, 5, 2, 3, 3, 5
Offset: 1

Author

Charles Paul, Feb 01 2019

Keywords

Comments

Let U(k) denote the multiplicative group mod k. a(n) = smallest generator for U(A033948(n)). - N. J. A. Sloane, Mar 10 2019

Examples

			For n=2, A033948(2) = 2, U(2) is generated by 1.
For n=14, A033948(14) = 18, and U(18) is generated by both 5 and 11; here we select the smallest generator, 5, so a(14) = 5.
		

Crossrefs

Cf. A033948 (numbers that have a primitive root), A306253, A081888 (positions of records), A081889 (record values). First column of A046147.

Programs

  • Maple
    0,op(subs(FAIL=NULL, map(numtheory:-primroot,[$2..1000]))); # Robert Israel, Mar 10 2019
  • Mathematica
    Array[Take[PrimitiveRootList@ #, UpTo[1]] &, 210] // Flatten (* Michael De Vlieger, Feb 02 2019 *)
  • Python
    from math import gcd
    roots = [0]
    for n in range(2,140):
        # find U(n)
        un = [i for i in range(1,n) if gcd(i,n) == 1]
        # for each element in U(n), check if it's a generator
        order = len(un)
        is_cyclic = False
        for cand in un:
            is_gen = True
            run = 1
            # If it cand^x = 1 for some x < order, it's not a generator
            for _ in range(order-1):
                run = (run * cand) % n
                if run == 1:
                    is_gen = False
                    break
            if is_gen:
                roots.append(cand)
                is_cyclic = True
                break
    print(roots)

Extensions

More terms from Michael De Vlieger, Feb 02 2019
Edited by N. J. A. Sloane, Mar 10 2019
Edited by Robert Israel, Mar 10 2019

A306253 Largest primitive root mod A033948(n).

Original entry on oeis.org

0, 1, 2, 3, 3, 5, 5, 5, 7, 8, 11, 5, 14, 11, 15, 19, 21, 23, 19, 23, 27, 24, 31, 35, 33, 35, 34, 43, 45, 47, 47, 51, 47, 55, 56, 59, 55, 63, 69, 68, 69, 77, 77, 75, 80, 77, 86, 91, 92, 89, 99, 101, 103, 104, 103, 110, 115, 117, 115, 123, 118, 128, 117, 134, 135
Offset: 1

Author

Charles Paul, Feb 01 2019

Keywords

Comments

Let U(k) denote the multiplicative group mod k. a(n) = largest generator for U(A033948(n)). - N. J. A. Sloane, Mar 10 2019

Examples

			For n=2, U(n) is generated by 1.
For n=14, A033948(14) = 18, and, U(n) is generated by both 5 and 11; here we select the largest generator, 11, so a(14) = 11.
		

Crossrefs

See A306252 for smallest roots and A033948 for the sequence of numbers that have a primitive root.

Programs

  • Maple
    f:= proc(b) local x, t;
      t:= numtheory:-phi(b);
      for x from b-1 by -1 do if igcd(x,b) = 1 and numtheory:-order(x,b)=t then return x fi od
    end proc:
    f(1):= 0:
    cands:= select(t -> t=1 or numtheory:-primroot(t) <> FAIL, [$1..1000]):
    map(f, cands); # Robert Israel, Mar 10 2019
  • Mathematica
    Join[{0}, Last /@ DeleteCases[PrimitiveRootList[Range[1000]], {}]] (* Jean-François Alcover, Jun 18 2020 *)
  • Python
    def gcd(x, y):
        # Euclid's Algorithm
        while(y):
            x, y = y, x % y
        return x
    roots = [0]
    for n in range(2, 140):
        # find U(n)
        un = [i for i in range(n, 0, -1) if (gcd(i, n) == 1)]
        # for each element in U(n), check if it's a generator
        order = len(un)
        is_cyclic = False
        for cand in un:
            is_gen = True
            run = 1
            # If it cand^x = 1 for some x < order, it's not a generator
            for _ in range(order-1):
                run = (run * cand) % n
                if run == 1:
                    is_gen = False
                    break
            if is_gen:
                roots.append(cand)
                is_cyclic = True
                break
    print("roots:", roots)

Extensions

Edited by N. J. A. Sloane, Mar 10 2019.