Find the nth base-b digit of (b^k-1)^-2
APL (Dyalog Extended), 31 bytes
(⎕D,⎕A)⊃⍨⊃⎕⌽¯1⌽,⍉⎕(⊣⊤⍳⍤*~*-2⍨)⎕
Try it online!
A full program that takes numbers from stdin in the order of k
, b
, n
. n
being 1-based cost me 3 bytes ¯1⌽
.
How it works
The main mathematical trick is well explained in Neil's answer. The gist is that the repeating part of the base-b
representation consists of length-k
base-b
digits of 0..b^k-1
, except b^k-2
.
This answer implements it very literally: list all repeating base-b
digits, cyclically fetch n
th digit from it, and convert it to 0-9A-Z
. Cyclic indexing uses ngn's trick.
⎕(...)⎕ ⍝ Take k (the right) and b (the left) from stdin
⍳⍤*~*-2⍨ ⍝ Create a list of 0..b^k-1, and remove the number b^k-2
⊣⊤ ⍝ Convert these numbers into base-b digits into columns
,⍉ ⍝ Transpose and flatten to get the repeating base-b digits
⊃⎕⌽¯1⌽ ⍝ Take n from stdin and get the nth digit cyclically
(⎕D,⎕A)⊃⍨ ⍝ Convert the number to the corresponding char in 0-9A-Z