%I #31 Jul 26 2022 12:45:28
%S 1,2,1,2,1,4,1,2,1,2,1,4,1,2,1,2,1,4,1,2,1,2,1,4,1,2,1,2,1,6,1,2,1,2,
%T 1,4,1,2,1,2,1,4,1,2,1,2,1,4,1,2,1,2,1,4,1,2,1,2,1,6,1,2,1,2,1,4,1,2,
%U 1,2,1,4,1,2,1,2,1,4,1,2,1,2,1,4,1,2,1,2,1,6,1,2,1,2,1,4,1,2,1,2,1,4,1,2,1,2
%N Smallest k such that gcd(n,k) = gcd(n+1,k+1).
%C a(n) = least m>0 such that gcd(n!+1+m,n-m) = 1. [_Clark Kimberling_, Jul 21 2012]
%C From _Antti Karttunen_, Jan 26 2014: (Start)
%C a(n-1)+1 = A053669(n) = Smallest k >= 2 coprime to n = Smallest prime not dividing n.
%C Note that a(n) is equal to A235918(n+1) for the first 209 values of n. The first difference occurs at n=210 and A235921 lists the integers n for which a(n) differs from A235918(n+1).
%C (End)
%H Clark Kimberling & Antti Karttunen, <a href="/A071222/b071222.txt">Table of n, a(n) for n = 0..10001</a> (Terms up to n=1000 from Kimberling)
%F Asymptotic mean: Limit_{m->oo} (1/m) * Sum_{k=1..m} a(k) = A249270 - 1. - _Amiram Eldar_, Jul 26 2022
%t sgcd[n_]:=Module[{k=1},While[GCD[n,k]!=GCD[n+1,k+1],k++];k]; Array[sgcd,110] (* _Harvey P. Dale_, Jul 13 2012 *)
%o (PARI) for(n=1,140,s=1; while(gcd(s,n)<gcd(n+1,s+1),s++); print1(s,","))
%o (Scheme) (define (A071222 n) (let loop ((k 1)) (cond ((= (gcd n k) (gcd (+ n 1) (+ k 1))) k) (else (loop (+ 1 k)))))) ;; _Antti Karttunen_, Jan 26 2014
%o (Haskell)
%o a071222 n = head [k | k <- [1..], gcd (n + 1) (k + 1) == gcd n k]
%o -- _Reinhard Zumkeller_, Oct 01 2014
%Y One less than A053669(n+1).
%Y Cf. also A007978, A055874, A235918, A235921, A249270.
%K easy,nonn
%O 0,2
%A _Benoit Cloitre_, Jun 10 2002
%E Added a(0)=1. - _N. J. A. Sloane_, Jan 19 2014