Number of ways to generate sequence by dividing by 3 or subtracting 1 
A sequence of positive integers is formed by following two rules:


$\bullet$ If a term of the sequence is a multiple of 3, the following term is generated by dividing the current term by 3.


$\bullet$ If a term of the sequence is not a multiple of 3, the following term is generated by subtracting 1 from the current term.


If the first term of the sequence is a three-digit integer and the 6th term is 1, what is the sum of all possible first terms?


How can I do this quickly without bashing it out backwards (starting at 1 and either 1. adding 1 or 2. Multiplying by 3)? There would also be the constraint that you can't add 1 three times in a row, since you have to divide if the number is divisible by 3.
 A: Clearly the number can be obtained by starting with $1$ and doing one of the following $5$ times:

*

*multiplying by $3$


*adding $1$
If we multiply by $3$ $k$ times then the largest number possible is $(6-k)3^k$ and the smallest number possible is $3^k+(5-k)$
We want our number to be between $100$ and $999$.
You can check the $5$ values of $k$ and see that only $k=4$ and $k=5$ are large enough.
When $k=5$ the number that works is $243$ and when $k=4$ there are $2$ ways that are large enough which are $162$ and $108$.
A: What if you consider your numbers in base $3$?  If the $6$th term is $1$, the fifth term can be either $10_3$ or $2_3$.  If the fifth term is $10_3$, the fourth term can be either $11_3$ or $20_3$.  Note that to get to the previous term, we either add $1$ to the final digit (assuming the last digit isn't a $2$)or append a $0$.  Finally, we have $100=10201_3$.  Our solutions in base $3$ are then $100000_3, 20000_3,$ or $11000_3$.  The sum of these are then $27(4+6+9)=27(19)=513$.
