OFFSET
1,2
COMMENTS
Rearrangement of the positive integers.
Any sequence defined in this manner (that is, a(1) is any positive integer and a(n+1) is the smallest integer not occurring earlier and coprime to Sum_{j=1..n} a(j)) is a rearrangement of all positive integers. This property is used by problem 4 of Chinese High School Mathematical Olympiad in 2018. - Shu Shang, Sep 29 2021
LINKS
FORMULA
For n > 6: a(n) = n-2 for n mod 4 = 0, a(n) = n-1 for n mod 4 = 1, a(n) = n+1 for n mod 4 = 2, a(n) = n+2 for n mod 4 = 3. - Klaus Brockhaus, Nov 30 2003
EXAMPLE
1+2+4 = 7, 3 is the smallest number not occurring earlier and coprime to 7, hence a(4) = 3.
PROG
(PARI) used(k, v)=b=0; j=1; while(b<1&&j<=length(v), if(v[j]==k, b=1, j++)); b
{print1(s=1, ", "); v=[s]; for(n=1, 72, j=1; k=2; while(used(k, v)||gcd(k, s)>1, k++); v=concat(v, k); s=s+k; print1(k, ", "))}
(PARI) {print1(1, ", ", 2, ", ", 4, ", ", 3, ", ", 7, ", ", 5, ", "); for(n=7, 73, m=n%4; d=(if(m==0, -2, if(m==1, -1, if(m==2, 1, 2)))); print1(n+d, ", "))}
(Haskell)
import Data.List (delete)
a084385 n = a084385_list !! (n-1)
a084385_list = 1 : f [2..] 1 where
f xs s = g xs where
g (y:ys) = if gcd s y == 1 then y : f (delete y xs) (s + y) else g ys
-- Reinhard Zumkeller, Aug 15 2015
KEYWORD
nonn
AUTHOR
Amarnath Murthy, May 29 2003
EXTENSIONS
Edited, corrected and extended by Klaus Brockhaus, May 29 2003
STATUS
approved