login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Smallest triangular number with digit sum n (or 0 if no such number exists).
5

%I #22 Aug 21 2024 12:17:40

%S 1,0,3,0,0,6,0,0,36,28,0,66,0,0,78,0,0,378,496,0,1596,0,0,8385,0,0,

%T 5778,5995,0,8778,0,0,47895,0,0,67896,58996,0,196878,0,0,468996,0,0,

%U 887778,1788886,0,4896885,0,0,5897895,0,0,13999986,15997996,0,38997696

%N Smallest triangular number with digit sum n (or 0 if no such number exists).

%C From _Jon E. Schoenfield_, Dec 04 2021: (Start)

%C a(n) = 0 iff n == (2,4,5,7,8) mod 9.

%C Nonzero terms are not nondecreasing; e.g., a(9)=36 > a(10)=28.

%C (End)

%H Jon E. Schoenfield, <a href="/A062688/b062688.txt">Table of n, a(n) for n = 1..168</a>

%e 66 is the smallest triangular number with digit sum 12, so a(12)=66.

%t (With[{tbl={#,Total[IntegerDigits[#]]}&/@Accumulate[Range[9000]]},Table[SelectFirst[ tbl,#[[2]] ==n&],{n,60}]]/.Missing["NotFound"]->{0,0})[[;;,1]] (* _Harvey P. Dale_, Aug 21 2024 *)

%o (PARI) a(n) = if (vecsearch([2,4,5,7,8], n % 9), return (0)); my(k=1); while (sumdigits(k*(k+1)/2) != n, k++); k*(k+1)/2; \\ _Michel Marcus_, Dec 12 2021

%Y Cf. A000217, A007953, A055264, A068808.

%K base,nonn

%O 1,3

%A _Erich Friedman_, Jul 04 2001