OFFSET
1,2
COMMENTS
It is easy to show that a(n) always exists and in fact has at most n digits [Wu, 2014]. - N. J. A. Sloane, Jun 13 2014
a(10^k) = 10^k and a(10^k - 1) = (10^(9k) - 1) / 9 for all k. Is a(n) < a(10^k - 1) for all n < 10^k - 1? - David Radcliffe, Aug 01 2025
LINKS
Chai Wah Wu, Table of n, a(n) for n = 1..9998 (first 2000 terms from T. D. Noe [and Ed Pegg Link])
Ed Pegg Jr., 'Binary' Puzzle.
Eric M. Schmidt, Sage code to compute this sequence.
Chai Wah Wu, Pigeonholes and repunits, Amer. Math. Monthly, 121 (2014), 529-533.
FORMULA
a(n) = n*A079339(n). - Jonathan Sondow, Jun 15 2014
a(m*2^a*5^b) = a(m) * 10^max{a,b} for gcd(m,10) = 1. - Jianing Song, Apr 22 2026
MAPLE
f:= proc(n)
local L, x, m, r, k, j;
if n<2 then return n fi;
for x from 2 to n-1 do L[0, x]:= 0 od:
L[0, 0]:= 1: L[0, 1]:= 1;
for m from 1 do
if L[m-1, (-10^m) mod n] = 1 then break fi;
L[m, 0]:= 1;
for k from 1 to n-1 do
L[m, k]:= max(L[m-1, k], L[m-1, k-10^m mod n])
od;
od;
r:= 10^m; k:= -10^m mod n;
for j from m-1 by -1 to 1 do
if L[j-1, k] = 0 then
r:= r + 10^j; k:= k - 10^j mod n;
fi
od;
if k = 1 then r:= r + 1 fi;
r
end proc:
seq(f(n), n=1..100); # Robert Israel, Feb 09 2016
MATHEMATICA
a[n_] := For[k = 1, True, k++, b = FromDigits[ IntegerDigits[k, 2] ]; If[Mod[b, n] == 0, Return[b]]]; a[0] = 0; Table[a[n], {n, 0, 34}] (* Jean-François Alcover, Jun 14 2013, after Reinhard Zumkeller *)
With[{c=Rest[Union[FromDigits/@Flatten[Table[Tuples[{1, 0}, i], {i, 10}], 1]]]}, Join[{0}, Flatten[ Table[ Select[c, Divisible[#, n]&, 1], {n, 40}]]]] (* Harvey P. Dale, Dec 07 2013 *)
PROG
(Haskell)
a004290 0 = 0
a004290 n = head [x | x <- tail a007088_list, mod x n == 0]
-- Reinhard Zumkeller, Jan 10 2012
(Python) def A004290(n):
if n > 0:
for i in range(1, 2**n):
x = int(bin(i)[2:])
if not x % n:
return x
return 0
# Chai Wah Wu, Dec 30 2014
(PARI) a(n) = {if( n==0, return (0)); my(m = n); while (vecmax(digits(m)) != 1, m+=n); m; } \\ Michel Marcus, Feb 09 2016, May 27 2020
(PARI) apply( {A004290(n)=for(k=1, 2^n, (t=fromdigits(binary(k)))%n||return(t))}, [1..44]) \\ M. F. Hasler, Mar 04 2025
CROSSREFS
KEYWORD
nonn,base,nice
AUTHOR
EXTENSIONS
Initial 0 deleted and offset corrected by N. J. A. Sloane, Jan 31 2024
STATUS
approved
