login
A001670
k appears k times (k even).
7
2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
OFFSET
1,1
LINKS
FORMULA
a(n) = 2*floor(1/2 + sqrt(n)). - Antonio Esposito, Jan 21 2002; corrected by Branko Curgus, May 11 2010
With a different offset: g.f. = Sum_{j>=0} 2*x^(j^2+i)/(1-x). - Ralf Stephan, Mar 11 2003
From Branko Curgus, May 11 2010: (Start)
a(n) = a(n - a(n-2)) + 2; a(1)=2, a(2)=2.
a(n) = 2*round(sqrt(n)). (End)
G.f.: x^(3/4)*theta_2(0,x)/(1-x) where theta_2 is the second Jacobi theta function. - Robert Israel, Jan 14 2015
a(n) = 2*floor((sqrt(4*n-3)+1)/2). - Néstor Jofré, Apr 24 2017
MAPLE
seq(2*n $ 2*n, n = 1 .. 10); # Robert Israel, Jan 14 2015
MATHEMATICA
a[1]=2, a[2]=2, a[n_]:=a[n]=a[n-a[n-2]]+2 (* Branko Curgus, May 11 2010 *)
Flatten[Table[Table[n, {n}], {n, 2, 16, 2}]] (* Harvey P. Dale, May 31 2012 *)
PROG
(Magma) [2*Round(Sqrt(n)): n in [1..70]]; // Vincenzo Librandi, Jun 23 2011
(PARI) a(n)=round(sqrt(n))<<1 \\ Charles R Greathouse IV, Jun 23 2011
(MATLAB) a = @(n) 2*floor((sqrt(4*n-3)+1)/2); % handle function // Néstor Jofré, Apr 24 2017
(Python)
from math import isqrt
def A001670(n): return (m:=isqrt(n))+int((n-m*(m+1)<<2)>=1)<<1 # Chai Wah Wu, Jul 29 2022
CROSSREFS
Equals A130829(n) - 1.
Sequence in context: A261009 A375347 A239896 * A100144 A076222 A177692
KEYWORD
nonn,easy
EXTENSIONS
Offset changed from 2 to 1 by Vincenzo Librandi, Jun 23 2011
STATUS
approved