%I #18 Oct 16 2021 13:48:30
%S 10,16,14,2,10,2,6,4,10,10,10,2,14,2,10,8,6,4,10,10,10,16,14,2,10,2,6,
%T 4,10,10,10,2,14,2,10,8,6,4,10,10,10,16,14,2,10,2,6,4,10,10,10,2,14,2,
%U 10,8,6,4,10,10,10,16,14,2,10,2,6,4,10,10,10,2,14,2,10,8,6,4,10,10,10
%N Least k>0 such that the last digit of (n+k)^(n+k) is the same as the last digit of n^n.
%H <a href="/index/Rec#order_20">Index entries for linear recurrences with constant coefficients</a>, signature (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1).
%F a(n) is periodic with period (10, 16, 14, 2, 10, 2, 6, 4, 10, 10, 10, 2, 14, 2, 10, 8, 6, 4, 10, 10, 10) of length 20
%t ld[n_]:=Module[{ldn=Mod[n^n,10],k=1},While[Mod[(n+k)^(n+k),10] != ldn,k++];k]; Array[ld, 90] (* _Harvey P. Dale_, Sep 07 2012 *)
%t LinearRecurrence[{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},{10, 16, 14, 2, 10, 2, 6, 4, 10, 10, 10, 2, 14, 2, 10, 8, 6, 4, 10, 10},81] (* _Ray Chandler_, Aug 26 2015 *)
%o (PARI) a(n)=if(n<0,0,s=1; while(abs((n+s)^(n+s)%10-n^n%10)>0,s++); s)
%o (Python)
%o def a(n):
%o k, target = 1, pow(n, n, 10)
%o while pow(n+k, n+k, 10) != target: k += 1
%o return k
%o print([a(n) for n in range(1, 82)]) # _Michael S. Branicky_, Oct 16 2021
%K base,easy,nonn
%O 1,1
%A _Benoit Cloitre_, Aug 13 2002
|