ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1261. Tips

it seems so easy but can't solve it;
Posted by Dulat_TKTL 30 Jan 2006 15:14
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;
Posted by Dulat_TKTL 2 Feb 2006 14:15
must we use array
Re: it seems so easy but can't solve it;
Posted by Michael Rybak (accepted@ukr.net) 3 Feb 2006 19:05
I did.
Re: it seems so easy but can't solve it;
Posted by Aybek_TKTL 3 Feb 2006 19:58
how?
Michael Rybak (accepted@ukr.net) wrote 3 February 2006 19:05
I did.
Re: it seems so easy but can't solve it;
Posted by Michael Rybak (accepted@ukr.net) 3 Feb 2006 21:50
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