login
Lexicographically earliest infinite sequence such that a(i) = a(j) => f(i) = f(j), for all i, j >= 1, where f(p) = p-nextprime(p) for primes p, and f(n) = n for all other numbers.
3

%I #7 Aug 10 2020 00:19:40

%S 1,2,3,4,3,5,6,7,8,9,3,10,6,11,12,13,3,14,6,15,16,17,18,19,20,21,22,

%T 23,3,24,18,25,26,27,28,29,6,30,31,32,3,33,6,34,35,36,18,37,38,39,40,

%U 41,18,42,43,44,45,46,3,47,18,48,49,50,51,52,6,53,54,55,3,56,18,57,58,59,60,61,6,62,63,64,18,65,66

%N Lexicographically earliest infinite sequence such that a(i) = a(j) => f(i) = f(j), for all i, j >= 1, where f(p) = p-nextprime(p) for primes p, and f(n) = n for all other numbers.

%C Restricted growth sequence transform of function f defined as: f(n) = -{distance to the next larger prime} when n is a prime, otherwise f(n) = -n.

%C For all i, j:

%C a(i) = a(j) => A305801(i) = A305801(j),

%C a(i) = a(j) => A336852(i) = A336852(j),

%C a(i) = a(j) => A336853(i) = A336853(j).

%H Antti Karttunen, <a href="/A336855/b336855.txt">Table of n, a(n) for n = 1..100000</a>

%H <a href="/index/Pri#gaps">Index entries for primes, gaps between</a>

%o (PARI)

%o up_to = 100000;

%o rgs_transform(invec) = { my(om = Map(), outvec = vector(length(invec)), u=1); for(i=1, length(invec), if(mapisdefined(om,invec[i]), my(pp = mapget(om, invec[i])); outvec[i] = outvec[pp] , mapput(om,invec[i],i); outvec[i] = u; u++ )); outvec; };

%o A336855aux(n) = if(isprime(n),n-nextprime(1+n),n);

%o v336855 = rgs_transform(vector(up_to,n,A336855aux(n)));

%o A336855(n) = v336855[n];

%Y Cf. also A001359 (positions of 3's), A305801, A319704, A331304, A336852, A336853.

%K nonn

%O 1,2

%A _Antti Karttunen_, Aug 09 2020