Can this number be written in (3^x) - 1 format? Challenge:

Create a program that accepts a positive integer and checks if it can be written in the form of (3^x)-1, where X is another positive integer.

If it can, output X

If it can't, output -1 or a falsy statement.

Example inputs/outputs

Input:

2


It can be written as (3^1) - 1, so we output x which is 1

Output:

1


Input:

26


26 can be written as (3^3) - 1, so we output x (3)

Output:

3


Input:

1024


1024 can't be written in the form of (3^x) - 1, so we output -1

Output:

-1


This is code-golf so least amount of bytes wins



Related OEIS: A024023
Mathematica, 21 16 bytes

-1&amp;@@Log[3,#+1]&amp;


Makes use of Mathematica's symbolic computation. If #+1 is a power of three then Log[3,#+1] will compute an integer result which is an atomic value. Otherwise we'll get Log[#+1]/Log[3] as is. Since this is not an atomic value, it's an expression which is always of the form head[val1,val2,...]. In this case it's actually something like Times[Power[Log[3], -1], Log[#+1]]. 

We distinguish between the two cases by applying another function to the result. What applying really does is that it replaces the head part of an expression. Since integer results are atomic, applying any function to them does nothing at all. In particular f @@ atom == atom.

However, in the other case, the head does get replaced. The function we're using is -1&amp; which is a simple function that ignores its arguments and returns -1. So we get something -1&amp;[Power[Log[3], -1], Log[#+1]] in non-integer cases, which evaluates directly to -1. Special casing via magic.