login
Numbers k such that k, k + 1 and k + 2 are 3 consecutive Harshad numbers.
33

%I #20 Mar 17 2024 07:37:02

%S 1,2,3,4,5,6,7,8,110,510,511,1010,1014,1015,2022,2023,2464,3030,3031,

%T 4912,5054,5831,7360,8203,9854,10010,10094,10307,10308,11645,12102,

%U 12103,12255,12256,13110,13111,13116,13880,14704,15134,17152,17575,18238,19600,19682

%N Numbers k such that k, k + 1 and k + 2 are 3 consecutive Harshad numbers.

%C Harshad numbers are also known as Niven numbers.

%C Cooper and Kennedy proved that there are infinitely many runs of 20 consecutive Niven numbers. Therefore this sequence is infinite. - _Amiram Eldar_, Jan 03 2020

%D Jean-Marie De Koninck, Those Fascinating Numbers, American Mathematical Society, 2009, p. 36, entry 110.

%H Robert Israel, <a href="/A154701/b154701.txt">Table of n, a(n) for n = 1..10000</a>

%H Curtis Cooper and Robert E. Kennedy, <a href="http://www.fq.math.ca/Scanned/31-2/cooper.pdf">On consecutive Niven numbers</a>, Fibonacci Quarterly, Vol. 21, No. 2 (1993), pp. 146-151.

%H Helen G. Grundman, <a href="https://www.fq.math.ca/Scanned/32-2/grundman.pdf">Sequences of consecutive Niven numbers</a>, Fibonacci Quarterly, Vol. 32, No. 2 (1994), pp. 174-175.

%H Wikipedia, <a href="http://en.wikipedia.org/wiki/Harshad_number">Harshad number</a>

%H Brad Wilson, <a href="http://www.fq.math.ca/Scanned/35-2/wilson.pdf">Construction of 2n consecutive n-Niven numbers</a>, Fibonacci Quarterly, Vol. 35, No. 2 (1997), pp. 122-128.

%e 110 is a term since 110 is divisible by 1 + 1 + 0 = 2, 111 is divisible by 1 + 1 + 1 = 3, and 112 is divisible by 1 + 1 + 2 = 4.

%p Res:= NULL: count:= 0:

%p state:= 1:

%p L:= [1]:

%p for n from 2 while count < 100 do

%p L[1]:=L[1]+1;

%p for k from 1 while L[k]=10 do L[k]:= 0;

%p if k = nops(L) then L:= [0$nops(L),1]; break

%p else L[k+1]:= L[k+1]+1 fi

%p od:

%p s:= convert(L,`+`);

%p if n mod s = 0 then

%p state:= min(state+1,3);

%p if state = 3 then count:= count+1; Res:= Res, n-2; fi

%p else state:= 0

%p fi

%p od:

%p Res; # _Robert Israel_, Feb 01 2019

%t nivenQ[n_] := Divisible[n, Total @ IntegerDigits[n]]; niv = nivenQ /@ Range[3]; seq = {}; Do[niv = Join[Rest[niv], {nivenQ[k]}]; If[And @@ niv, AppendTo[seq, k - 2]], {k, 3, 2*10^4}]; seq (* _Amiram Eldar_, Jan 03 2020 *)

%o (C) #include <stdio.h>

%o #include <conio.h>

%o int is_harshad(int n){

%o int i,j,count=0;

%o i=n;

%o while(i>0){

%o count=count+i%10;

%o i=i/10;

%o }

%o return n%count==0?1:0;

%o }

%o main(){

%o int k;

%o clrscr();

%o for(k=1;k<=30000;k++)

%o if(is_harshad(k)&&is_harshad(k+1)&&is_harshad(k+2))

%o printf("%d,",k);

%o getch();

%o return 0;

%o }

%o (Magma) f:=func<n|n mod &+Intseq(n) eq 0>; a:=[]; for k in [1..20000] do if forall{m:m in [0..2]|f(k+m)} then Append(~a,k); end if; end for; a; // _Marius A. Burtea_, Jan 03 2020

%o (Python)

%o from itertools import count, islice

%o def agen(): # generator of terms

%o h1, h2, h3 = 1, 2, 3

%o while True:

%o if h3 - h1 == 2: yield h1

%o h1, h2, h3 = h2, h3, next(k for k in count(h3+1) if k%sum(map(int, str(k))) == 0)

%o print(list(islice(agen(), 45))) # _Michael S. Branicky_, Mar 17 2024

%Y A subset of A005349.

%Y Cf. A060159, A141769, A328210, A328214, A330927, A330928, A330929, A330930, A330932.

%K nonn,base

%O 1,2

%A Avik Roy (avik_3.1416(AT)yahoo.co.in), Jan 14 2009, Jan 15 2009