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.

Showing 1-8 of 8 results.

A006257 Josephus problem: a(2*n) = 2*a(n)-1, a(2*n+1) = 2*a(n)+1.

Original entry on oeis.org

0, 1, 1, 3, 1, 3, 5, 7, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29
Offset: 0

Views

Author

Keywords

Comments

Write the numbers 1 through n in a circle, start at 1 and cross off every other number until only one number is left.
A version of the children's game "One potato, two potato, ...".
a(n)/A062383(n) = (0, 0.1, 0.01, 0.11, 0.001, ...) enumerates all binary fractions in the unit interval [0, 1). - Fredrik Johansson, Aug 14 2006
Iterating a(n), a(a(n)), ... eventually leads to 2^A000120(n) - 1. - Franklin T. Adams-Watters, Apr 09 2010
By inspection, the solution to the Josephus Problem is a sequence of odd numbers (from 1) starting at each power of 2. This yields a direct closed form expression (see formula below). - Gregory Pat Scandalis, Oct 15 2013
Also zero together with a triangle read by rows in which row n lists the first 2^(n-1) odd numbers (see A005408), n >= 1. Row lengths give A011782. Right border gives A000225. Row sums give A000302, n >= 1. See example. - Omar E. Pol, Oct 16 2013
For n > 0: a(n) = n + 1 - A080079(n). - Reinhard Zumkeller, Apr 14 2014
In binary, a(n) = ROL(n), where ROL = rotate left = remove the leftmost digit and append it to the right. For example, n = 41 = 101001_2 => a(n) = (0)10011_2 = 19. This also explains FTAW's comment above. - M. F. Hasler, Nov 02 2016
In the under-down Australian card deck separation: top card on bottom of a deck of n cards, next card separated on the table, etc., until one card is left. The position a(n), for n >= 1, from top will be the left over card. See, e.g., the Behrends reference, pp. 156-164. For the down-under case see 2*A053645(n), for n >= 3, n not a power of 2. If n >= 2 is a power of 2 the botton card survives. - Wolfdieter Lang, Jul 28 2020

Examples

			From _Omar E. Pol_, Jun 09 2009: (Start)
Written as an irregular triangle the sequence begins:
  0;
  1;
  1,3;
  1,3,5,7;
  1,3,5,7,9,11,13,15;
  1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31;
  1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,
   43,45,47,49,51,53,55,57,59,61,63;
...
(End)
From _Omar E. Pol_, Nov 03 2018: (Start)
An illustration of initial terms, where a(n) is the area (or number of cells) in the n-th region of the structure:
   n   a(n)       Diagram
   0    0     _
   1    1    |_|_ _
   2    1      |_| |
   3    3      |_ _|_ _ _ _
   4    1          |_| | | |
   5    3          |_ _| | |
   6    5          |_ _ _| |
   7    7          |_ _ _ _|
(End)
		

References

  • Erhard Behrends, Der mathematische Zauberstab, Rowolth Taschenbuch Verlag, rororo 62902, 4. Auflage, 2019, pp. 156-164. [English version: The Math Behind the Magic, AMS, 2019.]
  • R. L. Graham, D. E. Knuth and O. Patashnik, Concrete Mathematics. Addison-Wesley, Reading, MA, 1990, p. 10.
  • M. S. Petković, "Josephus problem", Famous Puzzles of Great Mathematicians, page 179, Amer. Math. Soc. (AMS), 2009.
  • Michel Rigo, Formal Languages, Automata and Numeration Systems, 2 vols., Wiley, 2014. Mentions this sequence - see "List of Sequences" in Vol. 2.
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
  • Paul Weisenhorn, Josephus und seine Folgen, MNU, 59(2006), pp. 18-19.

Crossrefs

Second column, and main diagonal, of triangle A032434.
Cf. A181281 (with s=5), A054995 (with s=3).
Column k=2 of A360099.

Programs

  • Coq
    Require Import ZArith.
    Fixpoint a (n : positive) : Z :=
    match n with
    | xH => 1
    | xI n' => (2*(a n') + 1)%Z
    | xO n' => (2*(a n') - 1)%Z
    end.
    (* Stefan Haan, Aug 27 2023 *)
  • Haskell
    a006257 n = a006257_list !! n
    a006257_list =
       0 : 1 : (map (+ 1) $ zipWith mod (map (+ 1) $ tail a006257_list) [2..])
    -- Reinhard Zumkeller, Oct 06 2011
    
  • Magma
    [0] cat [2*(n-2^Floor(Log(2,n)))+1: n in [1..100]]; // Vincenzo Librandi, Jan 14 2016
    
  • Maple
    a(0):=0: for n from 1 to 100 do a(n):=(a(n-1)+1) mod n +1: end do:
    seq(a(i),i=0..100); # Paul Weisenhorn, Oct 10 2010; corrected by Robert Israel, Jan 13 2016
    A006257 := proc(n)
        convert(n,base,2) ;
        ListTools[Rotate](%,-1) ;
        add( op(i,%)*2^(i-1),i=1..nops(%)) ;
    end proc: # R. J. Mathar, May 20 2016
    A006257 := n -> 2*n  - Bits:-Iff(n, n):
    seq(A006257(n), n=0..78); # Peter Luschny, Sep 24 2019
  • Mathematica
    Table[ FromDigits[ RotateLeft[ IntegerDigits[n, 2]], 2], {n, 0, 80}] (* Robert G. Wilson v, Sep 21 2003 *)
    Flatten@Table[Range[1, 2^n - 1, 2], {n, 0, 5}] (* Birkas Gyorgy, Feb 07 2011 *)
    m = 5; Range[2^m - 1] + 1 - Flatten@Table[Reverse@Range[2^n], {n, 0, m - 1}] (* Birkas Gyorgy, Feb 07 2011 *)
  • PARI
    a(n)=sum(k=1,n,if(bitxor(n,k)Paul D. Hanna
    
  • PARI
    a(n)=if(n, 2*n-2^logint(2*n,2)+1, 0) \\ Charles R Greathouse IV, Oct 29 2016
    
  • Python
    import math
    def A006257(n):
         return 0 if n==0 else 2*(n-2**int(math.log(n,2)))+1 # Indranil Ghosh, Jan 11 2017
    
  • Python
    def A006257(n): return bool(n&(m:=1<Chai Wah Wu, Jan 22 2023
    (C#)
    static long cs_A006257(this long n) => n == 0 ? 0 : 1 + (1 + (n - 1).cs_A006257()) % n; // Frank Hollstein, Feb 24 2021
    

Formula

To get a(n), write n in binary, rotate left 1 place.
a(n) = 2*A053645(n) + 1 = 2(n-msb(n))+1. - Marc LeBrun, Jul 11 2001. [Here "msb" = "most significant bit", A053644.]
G.f.: 1 + 2/(1-x) * ((3*x-1)/(2-2*x) - Sum_{k>=1} 2^(k-1)*x^2^k). - Ralf Stephan, Apr 18 2003
a(n) = number of positive integers k < n such that n XOR k < n. a(n) = n - A035327(n). - Paul D. Hanna, Jan 21 2006
a(n) = n for n = 2^k - 1. - Zak Seidov, Dec 14 2006
a(n) = n - A035327(n). - K. Spage, Oct 22 2009
a(2^m+k) = 1+2*k; with 0 <= m and 0 <= k < 2^m; n = 2^m+k; m = floor(log_2(n)); k = n-2^m; a(n) = ((a(n-1)+1) mod n) + 1; a(1) = 1. E.g., n=27; m=4; k=11; a(27) = 1 + 2*11 = 23. - Paul Weisenhorn, Oct 10 2010
a(n) = 2*(n - 2^floor(log_2(n))) + 1 (see comment above). - Gregory Pat Scandalis, Oct 15 2013
a(n) = 0 if n = 0 and a(n) = 2*a(floor(n/2)) - (-1)^(n mod 2) if n > 0. - Marek A. Suchenek, Mar 31 2016
G.f. A(x) satisfies: A(x) = 2*A(x^2)*(1 + x) + x/(1 + x). - Ilya Gutkovskiy, Aug 31 2019
For n > 0: a(n) = 2 * A062050(n) - 1. - Frank Hollstein, Oct 25 2021

Extensions

More terms from Robert G. Wilson v, Sep 21 2003

A145037 Number of 1's minus number of 0's in the binary representation of n.

Original entry on oeis.org

0, 1, 0, 2, -1, 1, 1, 3, -2, 0, 0, 2, 0, 2, 2, 4, -3, -1, -1, 1, -1, 1, 1, 3, -1, 1, 1, 3, 1, 3, 3, 5, -4, -2, -2, 0, -2, 0, 0, 2, -2, 0, 0, 2, 0, 2, 2, 4, -2, 0, 0, 2, 0, 2, 2, 4, 0, 2, 2, 4, 2, 4, 4, 6, -5, -3, -3, -1, -3, -1, -1, 1, -3, -1, -1, 1, -1, 1, 1, 3, -3, -1, -1, 1, -1, 1, 1, 3, -1, 1, 1
Offset: 0

Views

Author

Reikku Kulon, Sep 30 2008

Keywords

Comments

Column 2 of A144912 (which begins at n = 2).
Zeros in that column correspond to A031443.

Examples

			From _Michel Marcus_, Feb 12 2022: (Start)
Viewed as an irregular triangle:
   0;
   1;
   0,  2;
  -1,  1,  1, 3;
  -2,  0,  0, 2,  0, 2, 2, 4;
  -3, -1, -1, 1, -1, 1, 1, 3, -1, 1, 1, 3, 1, 3, 3, 5;
  ... (End)
		

Crossrefs

Cf. A037861 (negated), A031443 (indices of 0's), A144912, A000120.
Cf. A269735 (first differences), A268289 (partial sums).
Column k=1 of A360099.

Programs

  • Haskell
    a145037 0 = 0
    a145037 n = a145037 n' + 2*m - 1 where (n', m) = divMod n 2
    -- Reinhard Zumkeller, Jun 16 2011
    
  • Maple
    a:= n-> add(2*i-1, i=Bits[Split](n)):
    seq(a(n), n=0..90);  # Alois P. Heinz, Jan 18 2022
  • Mathematica
    Join[{0}, Table[Count[#, 1] - Count[#, 0] &[IntegerDigits[n, 2]], {n, 1, 90}]] (* Robert P. P. McKone, Feb 12 2022 *)
  • PARI
    A145037(n)=hammingweight(n)*2-logint(n<<1+!n,2) \\ M. F. Hasler, Mar 08 2018
    
  • Python
    result = [0]
    for n in range (1, 2**14 + 1):
        result.append(bin(n)[2:].count("1") - bin(n)[2:].count("0"))
    print(result[0:129]) # Karl-Heinz Hofmann, Jan 18 2022
    
  • Python
    def a(n): return (n.bit_count()<<1) - n.bit_length()
    print([a(n) for n in range(1, 2**14+1)]) # Michael S. Branicky, May 14 2024
    (C#)
    int A145037(int n)  {
        int result = 0;
        while(n > 0)  {
            result += 2 * (n % 2) - 1;
            n /= 2;
        }
        return result;
    } \\ Frank Hollstein, Dec 08 2022

Formula

a(n) = -A037861(n) for n >= 1.
a(n) = Sum_{i=1..k} (2*b[i] - 1) where b is the binary expansion of n and k is the number of bits in this binary expansion. - Michel Marcus, Jun 28 2021
From Aayush Soni Feb 12 2022: (Start)
Upper bound: a(n) <= floor(log_2(n+1)).
Lower bound: For n > 0, a(n) >= 1 - floor(log_2(n)).
If n is even, a(2^n) to a(2^(n+1)-1) inclusive are all odd and vice versa. (End)

Extensions

Renamed (using a Mar 08 2018 comment from M. F. Hasler) and edited by Jon E. Schoenfield, Jun 29 2021

A147991 Sequence S such that 1 is in S and if x is in S, then 3x-1 and 3x+1 are in S.

Original entry on oeis.org

1, 2, 4, 5, 7, 11, 13, 14, 16, 20, 22, 32, 34, 38, 40, 41, 43, 47, 49, 59, 61, 65, 67, 95, 97, 101, 103, 113, 115, 119, 121, 122, 124, 128, 130, 140, 142, 146, 148, 176, 178, 182, 184, 194, 196, 200, 202, 284, 286, 290, 292, 302, 304, 308, 310, 338, 340, 344, 346
Offset: 1

Views

Author

Clark Kimberling, Dec 07 2008

Keywords

Comments

Positive numbers that can be written in balanced ternary without a 0 trit. - J. Hufford, Jun 30 2015
Let S be the set of terms. Define c: Z -> P(R) so that c(m) is the translated Cantor ternary set spanning [m-0.5, m+0.5], and let C be the union of c(m) for all m in S U {0} U -S. C is the closure of the translated Cantor ternary set spanning [-0.5, 0.5] under multiplication by 3. - Peter Munn, Jan 31 2022

Examples

			0th generation: 1;
1st generation: 2 4;
2nd generation: 5 7 11 13.
		

Crossrefs

Cf. A006288, A351243 (non-quotients).
See also the related sequences listed in A191106.
One half of each position > 0 where A307744 sets or equals a record.
Cf. A030300.
Column k=3 of A360099.

Programs

  • Haskell
    import Data.Set (singleton, insert, deleteFindMin)
    a147991 n = a147991_list !! (n-1)
    a147991_list = f $ singleton 1 where
       f s = m : (f $ insert (3*m - 1) $ insert (3*m + 1) s')
             where (m, s') = deleteFindMin s
    -- Reinhard Zumkeller, Feb 21 2012, Jan 23 2011
    
  • Maple
    A147991:= proc(n) option remember; if n::even then 3*procname(n/2)-1 else 3*procname((n-1)/2)+1 fi end proc:
    A147991(1):= 1:
    [seq](A147991(i),i=1..1000); # Robert Israel, May 05 2014
  • Mathematica
    nn=346; s={1}; While[s1=Select[Union[s, 3*s-1, 3*s+1], # <= nn &];  s != s1, s=s1]; s
    a[ n_] := If[ n < -1 || n > 0, 3 a[Quotient[n, 2]] - (-1)^Mod[n, 2], 0]; (* Michael Somos, Dec 22 2018 *)
  • PARI
    {a(n) = if( n<-1 || n>0, 3*a(n\2) - (-1)^(n%2), 0)}; /* Michael Somos, Dec 22 2018 */
    
  • PARI
    a(n) = fromdigits(apply(b->if(b,1,-1),binary(n)), 3); \\ Kevin Ryde, Feb 06 2022

Formula

a(n) = 3*a(n/2) - 1 if n>=2 is even, 3*a((n-1)/2) + 1 if n is odd, a(0)=0. - Robert Israel, May 05 2014
G.f. g(x) satisfies g(x) = 3*(x+1)*g(x^2) + x/(1+x). - Robert Israel, May 05 2014
Product_{j=0..n-1} cos(3^j) = 2^(-n+1)*Sum_{i=2^(n-1)..2^n-1} cos(a(i)). - Gevorg Hmayakyan, Jan 15 2017
Sum_{i=2^(n-1)..2^n-1} cos(a(i)/3^(n-1)*Pi/2) = 0. - Gevorg Hmayakyan, Jan 15 2017
a(n) = -a(-1-n) for all n in Z. - Michael Somos, Dec 22 2018
For n > 0, A307744(2*a(2n)) = A307744(2*a(2n+1)) = A307744(2*a(n)) + 1. - Peter Munn, Jan 31 2022
a(n) mod 2 = A030300(n). - Alois P. Heinz, Jan 29 2023

A147992 Sequence S such that 1 is in S and if x is in S, then 4x-1 and 4x+1 are in S.

Original entry on oeis.org

1, 3, 5, 11, 13, 19, 21, 43, 45, 51, 53, 75, 77, 83, 85, 171, 173, 179, 181, 203, 205, 211, 213, 299, 301, 307, 309, 331, 333, 339, 341, 683, 685, 691, 693, 715, 717, 723, 725, 811, 813, 819, 821, 843, 845, 851, 853, 1195, 1197, 1203, 1205, 1227, 1229, 1235
Offset: 1

Views

Author

Clark Kimberling, Dec 07 2008

Keywords

Comments

Does every generation after the initial 1 contain a prime?

Examples

			0th generation: 1
1st generation: 3 5
2nd generation: 11 13 19 21
		

Crossrefs

Cf. A032925.
Column k=4 of A360099.

Formula

Product_{j=0..n-1} cos(4^j) = 2^(-n+1)*Sum_{i=2^(n-1)..2^n-1} cos(a(i)). - Gevorg Hmayakyan, Jan 15 2017
Sum_{i=2^(n-1)..2^n-1} cos(a(i)/4^(n-1)*Pi/2) = 0. - Gevorg Hmayakyan, Jan 15 2017
a(n) = 2*A032925(n-1) + 1 for n>=2. - Alois P. Heinz, Jan 29 2023

A147993 Sequence S such that 1 is in S and if x is in S, then 6x-1 and 6x+1 are in S.

Original entry on oeis.org

1, 5, 7, 29, 31, 41, 43, 173, 175, 185, 187, 245, 247, 257, 259, 1037, 1039, 1049, 1051, 1109, 1111, 1121, 1123, 1469, 1471, 1481, 1483, 1541, 1543, 1553, 1555, 6221, 6223, 6233, 6235, 6293, 6295, 6305, 6307, 6653, 6655, 6665, 6667, 6725, 6727, 6737, 6739
Offset: 1

Views

Author

Clark Kimberling, Dec 07 2008

Keywords

Comments

Does every generation after the initial 1 contain a prime?

Examples

			0th generation: 1
1st generation: 5 7
2nd generation: 29 31 41 43
		

Crossrefs

Cf. A032806.
Column k=6 of A360099.

Programs

  • Mathematica
    sss[n_]:={6n-1,6n+1}; NestList[Sort[Flatten[sss[#]]]&,{1},5]//Flatten (* Harvey P. Dale, Aug 06 2018 *)

Formula

Product_{j=0..n-1} cos(6^j) = 2^(-n+1)*Sum_{i=2^(n-1)..2^n-1} cos(a(i)). - Gevorg Hmayakyan, Jan 15 2017
Sum_{i=2^(n-1)..2^n-1} cos((a(i)/6^(n-1))*(Pi/2)) = 0. - Gevorg Hmayakyan, Jan 15 2017
a(n) = 2*A032806(n-1) + 1 for n>=2. - Alois P. Heinz, Jan 29 2023

A153777 Sequence S such that 1 is in S and if x is in S, then 5x-1 and 5x+1 are in S.

Original entry on oeis.org

1, 4, 6, 19, 21, 29, 31, 94, 96, 104, 106, 144, 146, 154, 156, 469, 471, 479, 481, 519, 521, 529, 531, 719, 721, 729, 731, 769, 771, 779, 781, 2344, 2346, 2354, 2356, 2394, 2396, 2404, 2406, 2594, 2596, 2604, 2606, 2644, 2646, 2654, 2656, 3594, 3596, 3604
Offset: 1

Views

Author

Clark Kimberling, Jan 02 2009

Keywords

Comments

Subsequences include A003463, A083065.
1st generation: 1
2nd generation: 4, 6
3rd generation: 19, 21, 29, 31
4th generation: 94, 96, 104, 106, 144, 146, 154, 156
Does every generation contain p or 2p for some prime p?

Crossrefs

Column k=5 of A360099.

Programs

  • Mathematica
    nxt[n_]:=Flatten[5#+{1,-1}&/@n]; Union[Flatten[NestList[nxt,{1},5]]] (* Harvey P. Dale, Dec 25 2012 *)

Formula

Product_{j=0..n-1} cos(5^j) = 2^(-n+1)*Sum_{i=2^(n-1)..2^n-1} cos(a(i)). - Gevorg Hmayakyan, Jan 15 2017
Sum_{i=2^(n-1)..2^n-1} cos(a(i)/5^(n-1)*Pi/2) = 0. - Gevorg Hmayakyan, Jan 15 2017
a(n) mod 2 = A030300(n). - Alois P. Heinz, Jan 29 2023

A360096 To get a(n), replace 0's in the binary expansion of n with (-1) and interpret the result in base n.

Original entry on oeis.org

0, 1, 1, 4, 11, 21, 41, 57, 439, 640, 909, 1222, 1859, 2354, 2953, 3616, 61167, 78303, 98837, 123121, 152379, 185641, 224113, 268227, 344999, 405601, 473901, 550423, 637363, 732483, 837929, 954305, 32472031, 37912414, 44058661, 50977186, 58741163, 67420476
Offset: 0

Views

Author

Alois P. Heinz, Jan 25 2023

Keywords

Comments

The empty bit string is used as binary expansion of 0, so a(0) = 0.

Crossrefs

Main diagonal of A360099.

Programs

  • Maple
    b:= proc(n, k) option remember; local m;
          `if`(n=0, 0, k*b(iquo(n, 2, 'm'), k)+2*m-1)
        end:
    a:= n-> b(n$2):
    seq(a(n), n=0..44);
    # second Maple program:
    a:= n-> (l-> add((2*l[i]-1)*n^(i-1), i=1..nops(l)))(Bits[Split](n)):
    seq(a(n), n=0..44);

Formula

a(n) = [x^n] g_n(x) where g_k(x) satisfies g_k(x) = k*(x+1)*g_k(x^2) + x/(1+x).
a(n) = A(n,n) where A(n,k) = k*A(floor(n/2),k)+2*(n mod 2)-1 for n>0, A(0,k)=0.
a(n) = A360099(n,n).
a(n) mod 2 = A057427(n) if n is even; a(n) mod 2 = A030300(n) if n is odd.

A359925 Numbers with easy multiplication table - the first 9 multiples of these numbers can be derived by either incrementing or decrementing the corresponding digits from the previous multiple.

Original entry on oeis.org

1, 9, 11, 89, 91, 109, 111, 889, 891, 909, 911, 1089, 1091, 1109, 1111, 8889, 8891, 8909, 8911, 9089, 9091, 9109, 9111, 10889, 10891, 10909, 10911, 11089, 11091, 11109, 11111, 88889, 88891, 88909, 88911, 89089, 89091, 89109, 89111, 90889, 90891, 90909, 90911
Offset: 1

Views

Author

Kiran Ananthpur Bacche, Jan 25 2023

Keywords

Comments

This is also the list of numbers having exactly one dot or one antidot in each box in the Decimal Exploding Dots notation.

Examples

			a(4) = 89. The first nine multiples of 89 are {089, 178, 267, 356, 445, 534, 623, 712, 801}. The digits in the hundreds place increment by 1, while the digits in the tens and units place decrement by 1. In the Decimal Exploding Dots notation, 89 is represented as DOT-ANTIDOT-ANTIDOT = 100 - 10 - 1 = 89
		

Crossrefs

Programs

  • Maple
    a:= proc(n) option remember;
          `if`(n=0, 0, 10*a(iquo(n, 2, 'm'))+2*m-1)
        end:
    seq(a(n), n=1..44);   # Alois P. Heinz, Jan 25 2023

Formula

a(n) = 10*a(floor(n/2))+2*(n mod 2)-1 for n>0, a(0)=0. - Alois P. Heinz, Jan 25 2023
a(n) = 2*A256290(n-1) + 1 for n>1. - Hugo Pfoertner, Jan 28 2023
Showing 1-8 of 8 results.