login
A282864
Lexicographic first permutation of the nonnegative integers such that the partial sums of s(n)*a(n) always remain nonnegative, where s(n) = +1 if a(n) is prime, -1 else.
6
0, 2, 1, 3, 4, 5, 7, 6, 11, 8, 9, 13, 10, 17, 12, 19, 14, 23, 15, 16, 29, 18, 31, 20, 21, 37, 22, 41, 24, 25, 43, 26, 27, 47, 28, 53, 30, 32, 59, 33, 34, 61, 35, 67, 36, 38, 71, 39, 40, 73, 42, 44, 79, 45, 83, 46, 48, 89, 49, 50, 97, 51, 52, 101, 54, 55, 103, 56, 107, 57, 58, 109, 60, 62, 113, 63, 64, 127, 65, 66, 131, 68, 69, 137, 70, 139, 72, 74, 149
OFFSET
0,2
COMMENTS
For n > 0, also absolute values of first differences of A282846.
EXAMPLE
Start with the smallest possible nonnegative number, 0. The partial sum remains 0 and is too small to allow subtraction of the nonprime number 1, so we add the least prime, 2, and the partial sum becomes 2. Now we can use 1, which will be subtracted, giving the partial sum 1. The smallest unused number is 3 which is prime and can be added, giving a sum of 4. This also allows us to use the next larger integer 4, subtracted since nonprime, to give a sum of 0. The prime number 5 can be added to yield 5, but the next larger integer is 6, too large to be subtracted, so the next prime, 7, comes before and is added to yield 12. Now 6 can be subtracted (sum = 6), but not the next unused number 8, nor 9, nor 10. Prior to using them, we add the next prime, 11, to yield sum = 17. Now 8 and then 9 can be subtracted, and so on.
PROG
(PARI) {print1(a=0); c=1; p=2; for(n=1, 99, print1(", "abs(a+0*if(a<c, a+=p; p=nextprime(p+1), a-=c; while(isprime(c++), ))-a)))}
CROSSREFS
Cf. A282846 for the partial sums of the signed terms.
Sequence in context: A370655 A082750 A048212 * A277518 A277383 A353730
KEYWORD
nonn
AUTHOR
Eric Angelini and M. F. Hasler, Feb 23 2017
STATUS
approved