OFFSET
1,5
COMMENTS
a(n) is the remainder when (2*a(n-1) + 1) is divided by n.
Can be generalized to a(n) = f(a(n-1)) mod n, where f is any polynomial function.
LINKS
Harry J. Smith, Table of n, a(n) for n = 1..1000
FORMULA
a(n) = (a(n-1) * 2 + 1) mod n.
EXAMPLE
0, (0*2+1) mod 2 = 1, (1*2+1) mod 3 = 0, (0*2+1) mod 4 = 1, (1*2+1) mod 5 = 3 (3*2+1) mod 6 = 1.
MATHEMATICA
nxt[{n_, a_}]:={n+1, Mod[2a+1, n+1]}; Transpose[NestList[nxt, {1, 0}, 80]][[2]] (* Harvey P. Dale, Feb 10 2014 *)
PROG
(PARI) { a=0; for (n=1, 1000, a=(2*a + 1)%n; write("b064434.txt", n, " ", a); ) } \\ Harry J. Smith, Sep 13 2009
(Magma) [n le 1 select n-1 else (2*Self(n-1)+1) mod n: n in [1..80]]; // Vincenzo Librandi, Jun 24 2018
(GAP) a:=[0];; for n in [2..90] do a[n]:=(2*a[n-1]+1) mod n; od; a; # Muniru A Asiru, Jun 24 2018
CROSSREFS
KEYWORD
nonn
AUTHOR
Jonathan Ayres (JonathanAyres(AT)btinternet.com), Oct 01 2001
STATUS
approved