cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 7, 8, 110, 510, 511, 1010, 1014, 1015, 2022, 2023, 2464, 3030, 3031, 4912, 5054, 5831, 7360, 8203, 9854, 10010, 10094, 10307, 10308, 11645, 12102, 12103, 12255, 12256, 13110, 13111, 13116, 13880, 14704, 15134, 17152, 17575, 18238, 19600, 19682
Offset: 1

Views

Author

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

Keywords

Comments

Harshad numbers are also known as Niven numbers.
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

Examples

			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.
		

References

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

Crossrefs

Programs

  • C
    #include 
    #include 
    int is_harshad(int n){
      int i,j,count=0;
      i=n;
      while(i>0){
        count=count+i%10;
        i=i/10;
      }
      return n%count==0?1:0;
    }
    main(){
      int k;
      clrscr();
      for(k=1;k<=30000;k++)
        if(is_harshad(k)&&is_harshad(k+1)&&is_harshad(k+2))
          printf("%d,",k);
      getch();
      return 0;
    }
    
  • Magma
    f:=func; 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
    
  • Maple
    Res:= NULL: count:= 0:
    state:= 1:
    L:= [1]:
    for n from 2 while count < 100 do
      L[1]:=L[1]+1;
      for k from 1 while L[k]=10 do L[k]:= 0;
        if k = nops(L) then L:= [0$nops(L),1]; break
        else L[k+1]:= L[k+1]+1 fi
      od:
      s:= convert(L,`+`);
      if n mod s = 0 then
         state:= min(state+1,3);
         if state = 3 then count:= count+1; Res:= Res, n-2; fi
      else state:= 0
      fi
    od:
    Res; # Robert Israel, Feb 01 2019
  • Mathematica
    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 *)
  • Python
    from itertools import count, islice
    def agen(): # generator of terms
        h1, h2, h3 = 1, 2, 3
        while True:
            if h3 - h1 == 2: yield h1
            h1, h2, h3 = h2, h3, next(k for k in count(h3+1) if k%sum(map(int, str(k))) == 0)
    print(list(islice(agen(), 45))) # Michael S. Branicky, Mar 17 2024