Let's define eleven-non-free
numbers:
If we consider a number as a string, then if any substring inside is a (non-zero) power of 11
, then this number is an eleven-non-free
number.
For example, 1123
is an eleven-non-free
number as 11
inside is 11^1
. Also 12154
is one as 121
is 11^2
. But 12345
is not, because we can't find any non-zero power of 11
inside.
So given a k, find the kth eleven-non-free
number. For example the 13th such number is 211
.
I don't know how to efficiently do it. the brute-force way is to increase i from 1 and check every number and count until the kth.
I guess we should consider strings with different length (1, 2, 3, 4, ...). then for each length, we try to fill in 11, 11^2, 11^3, etc and try to get all the combinations.
But it seems quite complicated as well.
Anyone?
This looks like an
O(klog^2(k))
algorithm:10^18
is really, really big. Brute force is not your friend.However, let us note some conveniences:
s
represents a eleven-non-free number, then trivially so doesd s
(whered
is a string of digits).k
-digit numbers are eleven-non-free, you could base that off of how manyk-1
-digit numbers are eleven-non-free.Finally, throw some binary-search style logic on top, and you should be able to find exactly which number is the N-th eleven-non-free number.