Trivial Case 1
will be represented using for all base .
Trivial Case 2
is represented as in base -2. For other bases, it will be .
Hint 1
For base , the number will be represented as .
Hint 2
For any number , it can be represented using s in base . The representation will be .
Hint 3
It is guaranteed that the number of bits in the lucky numbers will not exceed the number of bits in .
Hint 4
Avoid duplicates (Same numbers represented using only 1s in more than 2 bases).
Solution
Key Idea: For any number can be represented using only 1s in base , then will be lucky.
Generate strings of length etc. containing only 1s and figure out their values in base-2, 3, … considering the limits discussed above.
All the generated values will be lucky numbers.