CODE1 at SPOJ - cannot solve it
I am trying to solve the problem Secret Code on SPOJ, and it's obviously a math problem.
The full problem
For those who are lazy to go and read, it's like this:开发者_StackOverflow中文版
a0, a1, a2, ..., an - sequence of N numbers
B - a Complex Number (has both real and imaginary components)
X = a0 + a1*B + a2*(B^2) + a3*(B^3) + ... + an*(B^n)
So if you are given B and X, you should find a0, a1, ..an. I don't know how or where to start, because not even N is known, just X and B.
The problem is not as easy as expressing a number in a base B, because B is a complex number.
How can it be solved?
The key is that a0 .. an
are not arbitrary numbers, they're integers (otherwise, this wouldn't be possible in general). You're given the number X
, and are asked to express it in base B
. Why don't you start by working a few examples for a specific value of B
?
If I asked you to write 17 in base 2, would you be able to do that? Can you find a way to generalize the algorithm you use to bases other than 2?
精彩评论