|
|
back to boardDiscussion of Problem 1261. Tipsit seems so easy but can't solve it; I tried many times Please help!!!!!! Re: it seems so easy but can't solve it; Posted by Sid 1 Feb 2006 23:35 I don't remember exactly, I've solved this problem more than a year ago... But as I ramember it's easy to solve it if transform the numer in base of 3 format. P.S. Sorry for my poor english. Re: it seems so easy but can't solve it; must we use array Re: it seems so easy but can't solve it; I did. Re: it seems so easy but can't solve it; Re: it seems so easy but can't solve it; simply pre-generate all numbers that are sums of different powers of 3: 1. array <- 0 2. for item in array: array <- 3 + item 3. for item in array: array <- 9 + item 4. for item in array: array <- 27 + item 5. for item in array: array <- 81 + item ... until current power of 3 becomes larger than N * 3 + 1 (so it works for N = 1). You should prove that there's no use to check any powers of 3 that are larger than N * 3 + 1. Use the fact that 1 + 3 + 9 + 27 + .. + 3 ^ k = 3 ^ (k + 1) / 2, which means that no number in interval (3^k / 2, 3^k - 1) can be represented in that fashion. P.S. Note that the generated array will be sorted already, so no need to perform a sorting |
|
|