QUESTİON UPDATED:
Here is my problem:
$$2^x \equiv a \pmod{3^n}.$$
where, $a\not\equiv 0 \pmod{3}$ and $n\in \mathbb{Z^{+}}$
I want to learn that,
If,
$x=\left\{ {{3^n-\binom{n}{2}}-1}\right\}-f(n)$
$a=\sum_{j=0}^{n-1} 3^{n-j-1} 2^{3^j - \binom{j+1}{2} -1}=2^{3^{n-1}-\frac {n(n-1)}{2}-1}+3\cdot2^{{3^{n-2}-\frac {(n-1)(n-2)}{2}-1}}+3^2\cdot2^{{3^{n-3}-\frac {(n-2)(n-3)}{2}-1}}+\cdots+3^{n-1}$
Is it possible to find a general solution that depends on $n$?
I found these values with algorithmic ways:
$f(3)=16,f(4)=50,f(5)=94,f(6)=182,f(7)=400$
The exact form of the problem is:
$$2^{\left\{ {{3^n-\binom{n}{2}}-1}\right\}-f(n)}\equiv \sum_{j=0}^{n-1} 3^{n-j-1} 2^{3^j - \binom{j+1}{2} -1} \pmod{3^n}.$$
Question: For $f(n)$ is it possible to find a closed-form expression depends on $n$ , which that $f:\mathbb{N}\to\mathbb{N}$ such that $f(n)\in\mathbb{N}_{>0}$ ?
Small supplement:
Is it possible to find an algebraic closed form for $n\to\infty$ , can the simpler function $f'(n)$ be found, which gives $\lim_{n\to\infty} \frac{ f(n)}{f'(n)}=1$ ?
I mean, for example, if $f(n)=2^n+n^2+n$
We get, for $f'(n)=2^n.$
Is something like this possible?
We know that there is a solution, since $2$ is a primitive root for all powers of $3$.
For smallish values of $n$, we could solve this by iterating up the powers of three: solve $\bmod 3$ giving $x_1$, then calculate for the $3$ possible values $\bmod 9$, checking $x_1, x_1{+}2, x_1{+}4$ to find $x_2,$ then the $3$ possible values $\bmod 27$, $x_2, x_2{+}6, x_2{+}12$ to find $x_3$ etc. up to $x_n$.
At each step you have the (smallest) solution $x_k$ to $2^{\large{x_k}}\equiv a \bmod 3^k$. Then $x_k{+}\phi(3^k)$ and $x_k{+}2\phi(3^k)$ also solve this. Larger solutions will be greater than $\phi(3^{k+1})$ so one of these three values will be $x_{k+1}$, solving as the smallest solution to $2^{\large{x_{k+1}}}\equiv a \bmod 3^{k+1}$.
This process is relatively quick when you are using exponentiation by squaring.
For example this can quickly solve $2^x\equiv 4827836 \bmod 3^{17}$ as $x\equiv 16391041 \bmod \phi(3^{17})$. That is to say, $x = 16391041$ is the smallest solution and Euler's theorem means that you can add any multiple of $\phi(3^{17}) = 86093442$ for another valid result.
Your example of $2^x\equiv 8164718 \bmod 3^{15}$ solves to $x\equiv 5032989 \bmod \phi(3^{15})$.