login
a(n) = gcd(n,4).
12

%I #41 Sep 08 2022 08:45:19

%S 4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,

%T 2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,

%U 4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4,1,2,1,4

%N a(n) = gcd(n,4).

%C Period 4: repeat [4, 1, 2, 1]. - _Wesley Ivan Hurt_, Aug 31 2014

%H <a href="/index/Rec#order_04">Index entries for linear recurrences with constant coefficients</a>, signature (0,0,0,1).

%F a(n) = 1 + [2|n] + 2*[4|n] = 2 + (-1)^n + cos(n*Pi/2), where [x|y] = 1 when x divides y, 0 otherwise.

%F a(n) = a(n-4) for n>3.

%F Multiplicative with a(p^e) = gcd(p^e, 4). - _David W. Wilson_, Jun 12 2005

%F Dirichlet g.f.: (1 + 1/2^s + 2/4^s)*zeta(s). - _R. J. Mathar_, Feb 28 2011

%F G.f.: (4+x+2*x^2+x^3)/((1-x)*(1+x)*(1+x^2)). - _R. J. Mathar_, Apr 04 2011

%F a(n) = 1 + mod((n-1)^3, 4). - _Wesley Ivan Hurt_, Aug 31 2014

%F a(n) = 2 + cos(n*Pi) + cos(n*Pi/2). - _Wesley Ivan Hurt_, Jul 07 2016

%F E.g.f.: exp(-x) + 2*exp(x) + cos(x). - _Ilya Gutkovskiy_, Jul 07 2016

%p A109008:=n->gcd(n,4): seq(A109008(n), n=0..100); # _Wesley Ivan Hurt_, Aug 31 2014

%t Table[GCD[n, 4], {n, 0, 100}] (* _Wesley Ivan Hurt_, Aug 31 2014 *)

%o (Haskell)

%o a109008 = gcd 4

%o a109008_list = cycle [4,1,2,1] -- _Reinhard Zumkeller_, Nov 25 2013

%o (Magma) [Gcd(n,4) : n in [0..100]]; // _Wesley Ivan Hurt_, Aug 31 2014

%o (PARI) a(n)=gcd(n,4) \\ _Charles R Greathouse IV_, Oct 07 2015

%Y Cf. A109004.

%K nonn,easy,mult

%O 0,1

%A _Mitch Harris_