Task
For a given base \$n \ge 3\$, find the smallest positive integer \$m\$, when written in base \$n\$ and rotated right once, equals \$2m\$. The base-\$n\$ representation of \$m\$ cannot have leading zeroes.
The corresponding OEIS sequence is A087502, and its base-\$n\$ representation is A158877 (this one stops at \$n=11\$ because the answer for \$n=12\$ has a digit higher than 9). The OEIS page has some information about how to calculate the number:
a(n)
is the smallest integer of the formx*(n^d-1)/(2n-1)
for integerx
andd
, where1 < x < n
andd > 1
.x
is the last digit andd
is the number of digits ofa(n)
in basen
.Maple code:
A087502 := proc(n) local d, a; d := 1; a := n; while a>=n do d := d+1; a := denom((2^d-1)/(2*n-1)); od; return(max(2, a)*(n^d-1)/(2*n-1)); end proc;
You may output the result as a single integer or a list of base-10 or base-\$n\$ digits.
Examples and test cases
For \$ n = 3 \$, the answer is \$ m = 32 \$. \$ n = 4 \$ should give \$ m = 18 \$.
$$ m = 32_{10} = 1012_3 \rightarrow 2m = 64_{10} = 2101_3 \\ m = 18_{10} = 102_4 \rightarrow 2m = 36_{10} = 210_4 $$
n = 3
m = 32
m (base n) = 1012 or [1,0,1,2]
------------------------------
n = 4
m = 18
m (base n) = 102 or [1,0,2]
------------------------------
n = 10
m = 105263157894736842
m (base n) = 105263157894736842 or [1,0,5,2,6,3,1,5,7,8,9,4,7,3,6,8,4,2]
------------------------------
n = 33
m = 237184
m (base n) = 6jqd or [6,19,26,13]
------------------------------
n = 72
m = 340355112965862493
m (base n) = [6,39,19,45,58,65,32,52,26,13]
More I/O examples can be found on OEIS.
Scoring and winning criterion
Standard code-golf rules apply. Shortest solution in bytes wins.