OFFSET
1,2
COMMENTS
When dividing a number by N, the remainder can be at most N - 1. The largest sum of digits that an n-digit number can reach is 9*n. According to this, a(n) < 9*n is always the case.
Is the sequence strictly increasing? a(n) is achieved by a single n-digit number when n = 2, 3, 5, 19, 24, 27, 32, 38, ... (Cf. A348900) - Chai Wah Wu, Nov 02 2021
LINKS
David A. Corneth, Table of n, a(n) for n = 1..1780 (first 820 terms from Chai Wah Wu)
David A. Corneth, PARI program
Heinrich Hemme, Was ist der größtmögliche Rest? Hemmes mathematische Rätsel, Oct 28 2021.
Volker Wagner, Kleine Rechnerei, Knobelforum, Jan 24 2020.
EXAMPLE
79 = 15 mod 16
799 = 24 mod 25
9599 = 31 mod 32
98999 = 43 mod 44
599999 = 49 mod 50
8999998 = 58 mod 61
etc.
MAPLE
sod:=proc(n) # sum of digits
local N;
N:=convert(n, base, 10);
add(i, i=N);
end;
a:=proc(k)local n, i;
for n from 1 to k do
maxR||n:=0: # largest remainder
for i from 10^(n-1) to 10^n-1 do
if i mod sod(i)>maxR||n then
maxR||n:=i mod sod(i);
fi;
od:
od:
return(seq(maxR||n, n=1..k));
end;
MATHEMATICA
a[n_] := Max[Mod[#, (Plus @@ IntegerDigits[#])] & /@ Range[10^(n - 1), 10^n - 1]]; Array[a, 7] (* Amiram Eldar, Oct 31 2021 *)
PROG
(Python)
def sd(n): return sum(map(int, str(n)))
def a(n): return max(n%sd(n) for n in range(10**(n-1)+1, 10**n))
print([a(n) for n in range(1, 7)]) # Michael S. Branicky, Oct 31 2021
(PARI) See Corneth link
(Python)
from functools import lru_cache
from sympy.combinatorics.partitions import IntegerPartition
from sympy.utilities.iterables import partitions, multiset_permutations
@lru_cache(maxsize=None)
def intpartition(n, m): return tuple(''.join(str(d) for d in IntegerPartition(p).partition+[0]*(m-s)) for s, p in partitions(n, k=9, m=m, size=True))
def A348730(n):
l, c, k = 9*n, 0, 10**(n-1)
while l-1 > c:
c = max(c, max(s % l for s in (int(''.join(q)) for p in intpartition(l, n) for q in multiset_permutations(p)) if s >= k))
l -= 1
return c # Chai Wah Wu, Nov 03-08 2021
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Martin Renner, Oct 31 2021
EXTENSIONS
a(8)-a(10) from Michael S. Branicky, Oct 31 2021
More terms from David A. Corneth, Oct 31 2021
STATUS
approved