This question is closely related to: Conjectured primality test
Can you provide a proof or a counterexample for the following claim :
Conjecture. Let $n$ be a natural number greater than $2$. Then $n$ is prime if and only if
$$\sum_{k=1}^{n-1}\left(3^k-2\right)^{n-1} \;\equiv\; n \cdot 2^{n-1}-1 \pmod{\frac{3^n-1}{2}}$$
You can run this test here.
I was searching for a counterexample using the following two PARI/GP programs :
CE1(n1,n2)=
{
forcomposite(n=n1,n2,
s=sum(k=1,n-1,lift(Mod(3^k-2,(3^n-1)/2)^(n-1)));
if((Mod(s,(3^n-1)/2)==n*2^(n-1)-1),print("n="n)))
}
CE2(n1,n2)=
{
forprime(n=n1,n2,
s=sum(k=1,n-1,lift(Mod(3^k-2,(3^n-1)/2)^(n-1)));
if(!(Mod(s,(3^n-1)/2)==n*2^(n-1)-1),print("n="n)))
}
REMARK
More generally we can formulate the following criterion :
Let $b$ , $a$ and $n$ be a natural numbers, $b>a\geq 1$, $n>2$ and $n \not\in \{4,8,9\}$. Then $n$ is prime if and only if $$\displaystyle\sum_{k=1}^{n}\left(b^k\pm a\right)^{n-1} \equiv n \cdot a^{n-1} \pmod{\frac{b^n-1}{b-1}}$$
The general formula is not true.
For $1 \leq a < b < 20$ and $10 \leq n \leq100$ exceptions (i.e. values for $n$ for which the formula does not correctly state whether $n$ is prime) are:
Revealing some interesting patterns (and maybe a lower limit for the correctness of the formula). Also, interestingly, these values are all prime. However, taking $a=3$ and $b=4$ (this time with the $+$ sign) we get the counter-example $25$, a non-prime. In my very limited search I have found no other non-prime counter-examples greater than $10$. Also, all counter-examples seem to be powers of primes.
And yes, this does not directly help your original question with $b=3$ and $a=2$.