OFFSET
1,1
COMMENTS
To find such k, let n = 3^t*s, gcd(3,s) = 1. By Euler's totient theorem, k^n - 1 is divisible by 3^n is equivalent to k^s - 1 is divisible by 3^(3^t*s - t). For odd s, the solutions for k are k == 1 (mod 3^(3^t*s - t)); for even s, the solutions are k == +-1 (mod 3^(3^t*s - t)). This gives the formula below in formula section.
FORMULA
a(n) = 3^(n - A007949(n)) - (-1)^n.
EXAMPLE
For n = 3, k^3 == 1 (mod 27) implies k == 1 (mod 9), so a(3) = 10.
For n = 4, k^4 == 1 (mod 81) implies k == +-1 (mod 81), so a(4) = 80.
MATHEMATICA
Array[3^(# - IntegerExponent[#, 3]) - (-1)^# &, 31] (* Michael De Vlieger, Jul 05 2018 *)
PROG
(PARI) v(n) = valuation(n, 3);
a(n) = 3^(n - v(n)) - (-1)^n;
CROSSREFS
KEYWORD
nonn
AUTHOR
Jianing Song, Jul 05 2018
STATUS
approved