%I #23 Mar 31 2023 08:15:04
%S 9,84,999,9963,99972,999984,9999966,99999966,999999999,9999999828,
%T 99999999898,999999999853,9999999999936,99999999999783,
%U 999999999999984,9999999999999858,99999999999999939,999999999999999831,9999999999999999951,99999999999999999922,999999999999999999687
%N a(n) is the largest Niven (or Harshad) number with exactly n digits and not containing the digit 0.
%C This sequence is inspired by a problem, proposed by Argentina during the 39th International Mathematical Olympiad in 1998 at Taipei, Taiwan, but not used for the competition.
%C The problem asked for a proof that, for each positive integer n, there exists a n-digit number, not containing the digit 0 and that is divisible by the sum of its digits (see links: Diophante in French and Kalva in English).
%C This sequence lists the largest such n-digit integer.
%H Michael S. Branicky, <a href="/A348316/b348316.txt">Table of n, a(n) for n = 1..1000</a>
%H Diophante, <a href="http://www.diophante.fr/problemes-par-themes/arithmetique-et-algebre/a1-pot-pourri/3455-a1960-bon-souvenir-de-buenos-aires">Bon souvenir de Buenos-Aires</a>.
%H Kalva, <a href="https://prase.cz/kalva/short/sh98.html">39th IMO 1998 shortlisted problems, problem N7</a>.
%H <a href="/index/O#Olympiads">Index to sequences related to Olympiads</a>.
%F a(n) = A002283(n) = 10^n - 1 iff n is in A014950 (compare with A348150 formula).
%e 9963 has 4 digits, does not contain 0 and is divisible by 9+9+6+3 = 27 (9963 = 27*369), while there is no integer k with 9964 <= k <= 9999 that is divisible by sum of its digits, hence a(4) = 9963.
%t hQ[n_] := ! MemberQ[(d = IntegerDigits[n]), 0] && Divisible[n, Plus @@ d]; a[n_] := Module[{k = 10^n}, While[! hQ[k], k--]; k]; Array[a, 20] (* _Amiram Eldar_, Oct 11 2021 *)
%o (Python)
%o def a(n):
%o s, k = "9"*n, int("9"*n)
%o while '0' in s or k%sum(map(int, s)): k -= 1; s = str(k)
%o return k
%o print([a(n) for n in range(1, 22)]) # _Michael S. Branicky_, Oct 11 2021
%Y Cf. A002283, A005349, A014950, A217973, A348150, A348317, A348318.
%K nonn,base
%O 1,1
%A _Bernard Schott_, Oct 11 2021
%E More terms from _Amiram Eldar_, Oct 11 2021