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.

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
$$
