login
The sum of all odd numbers from 2n-1 up to the n-th odd nonprime.
1

%I #18 Aug 01 2024 01:30:34

%S 1,24,60,112,153,171,253,275,336,448,525,555,640,672,828,864,969,1155,

%T 1197,1320,1449,1495,1632,1680,1728,1875,2133,2407,2580,2640,2700,

%U 2760,2820,2880,3069,3264,3328,3672,3740,3808,3876,4248,4320,4551,4625,4864

%N The sum of all odd numbers from 2n-1 up to the n-th odd nonprime.

%H G. C. Greubel, <a href="/A163636/b163636.txt">Table of n, a(n) for n = 1..1000</a>

%F a(n) = A005408(n-1)+A005408(n)+...+A014076(n);

%F a(n) = ( A014076(n)+2*n-1 ) *( A014076(n)-2*n+3 )/4.

%e a(1)=1. a(2)=3+5+7+9=24. a(3)=5+7+9+11+13+15=60.

%p A014076 := proc(n) option remember; local a; if n = 1 then 1; else for a from procname(n-1)+2 by 2 do if not isprime(a) then RETURN(a) ; fi; od: fi; end:

%p A163636 := proc(n) local onpr; onpr := A014076(n) ; (onpr+2*n-1)*(onpr-2*n+3)/4; end: seq(A163636(n),n=1..80) ; # _R. J. Mathar_, Aug 08 2009

%t A014076 := Select[Range[1, 10299, 2], PrimeOmega[#] != 1 &]; Table[(A014076[[n]] + 2*n - 1)*(A014076[[n]] - 2*n + 3)/4, {n, 1, 50}] (* _G. C. Greubel_, Jul 31 2017 *)

%t Module[{nn=201,onp},onp=Select[Range[1,nn,2],!PrimeQ[#]&];Table[Total[ Range[ 2n-1,onp[[n]],2]],{n,Length[onp]}]] (* _Harvey P. Dale_, Jul 03 2020 *)

%o (Python)

%o from sympy import primepi

%o def A163636(n):

%o if n == 1: return 1

%o m, k, n2 = n-1, primepi(n) + n - 1 + (n>>1), (n<<1)-1

%o while m != k:

%o m, k = k, primepi(k) + n - 1 + (k>>1)

%o return (lambda x: (x+n2)*(x-n2+2)>>2)(m) # _Chai Wah Wu_, Jul 31 2024

%Y Cf. A005408, A014076.

%K nonn,easy

%O 1,2

%A _Juri-Stepan Gerasimov_, Aug 02 2009

%E Edited and a(21) corrected by _R. J. Mathar_, Aug 08 2009