Possible to determine position of number based on base 3 order of magnitude? I struggled with a good title for this - sorry if it ended up being confusing.  I am attempting to try to partition a series of decimal numbers (starting at 1) by base 3 orders of magnitude.  Essentially breaking them into ordered groups of 1,3,9,27,etc.  
I've had a hard time verbalizing what I am trying to do here (even to myself), so if this is still confusing perhaps the breakdown below will help?
1
  --- 3^0 is 1, so first partition contains 1 number
2
3
4
 --- 3^1 is 3, so second partition contains 3 numbers
5
6
7
8
9
10
11
12
13
 --- 3^2 is 9, so third partition contains 9 numbers
14
...
40
 --- 3^3 is 27, so fourth partition contains 27 numbers
and so on

Give a base 10 number, I would like to determine which partition it would be in based on the breakdown above.  So:
14 would return 3
13 would return 2
6 would return 2
1 would return 0

Can anyone suggest any ways to accomplish this or perhaps point me in the right direction?
My background isn't in mathematics so I apologize if it's unclear what I'm asking here or if this is a bad question.
 A: Let's focus on the last number $a_n$ of the $n$th partition (where $n$ starts from $0$):
$$
1, 4, 13, 40, \ldots
$$
Observe that it is the partial sum of a geometric series:
$$
a_n = 1 + 3 + \cdots + 3^n = \frac{3^{n + 1} - 1}{3 - 1}
$$
Taking the inverse function and using a ceiling function, we conclude that the $m$th number must be in the partition given by:
$$
p(m) = \lceil\log_3(2m + 1)\rceil - 1
$$
A: you could start with the number you want to evaluate and then start subtracting powers of 3, and the power that sends you into the negatives should be your partition. basically, you're starting with your number, and "crossing off" the first partition, then the next partition, and so on and so forth, until you reach the right partition
for example, $$14 - 3^0 = 14-1 = 13$$
$$13-3^1 = 13 - 3 = 10$$
$$10-3^2 = 10 - 9 = 1$$
$$1 - 3^3 = 1 - 27 = -26$$
so 14 is in the third partition
so, given some arbitrary number, say, 12577
$$12577-3^0 = 12576$$
$$12576-3^1 = 12573$$
$$12573-3^2=12564$$
$$12564-3^3=12537$$
$$12537-3^4=12456$$
$$12456-3^5=12213$$
$$12213-3^6=11484$$
$$11484-3^7=9297$$
$$9297-3^8=2736$$
$$2736-3^9=-16947$$
so 12577 should be in the $9^{th}$ partition
