login
a(n) is the greatest divisor of n divisible by the sum of its own digits.
2

%I #12 Sep 04 2023 11:19:30

%S 1,2,3,4,5,6,7,8,9,10,1,12,1,7,5,8,1,18,1,20,21,2,1,24,5,2,27,7,1,30,

%T 1,8,3,2,7,36,1,2,3,40,1,42,1,4,45,2,1,48,7,50,3,4,1,54,5,8,3,2,1,60,

%U 1,2,63,8,5,6,1,4,3,70,1,72,1,2,5,4,7,6,1,80

%N a(n) is the greatest divisor of n divisible by the sum of its own digits.

%C Numbers divisible by the sum of their digits are called Niven (or Harshad, or harshad) numbers (A007602).

%H Rémy Sigrist, <a href="/A360074/b360074.txt">Table of n, a(n) for n = 1..10000</a>

%H <a href="/index/Di#divisors">Index entries for sequences related to divisors</a>

%F a(n) = n iff n belongs to A005349.

%e For n = 32:

%e - the divisors of 32 are 1, 2, 4, 8, 16 and 32,

%e - 8 is divisible by 8 whereas 16 is not divisible by 1+6 and 32 is not divisible by 3+2,

%e - so a(32) = 8.

%t Table[Max[Select[Divisors[n],Mod[#,Total[IntegerDigits[#]]]==0&]],{n,80}] (* _Harvey P. Dale_, Sep 04 2023 *)

%o (PARI) a(n) = fordiv (n, d, my (t=n/d); if (t%sumdigits(t)==0, return (t)))

%Y Cf. A005349, A332268, A360073.

%K nonn,base,easy

%O 1,2

%A _Rémy Sigrist_, Jan 24 2023