>>865
a_k=2^(2^k)とすると、a_(k+1)=(a_k)^2なので
a_1≡4(mod7)
a_2≡2(mod7)
a_(2k+1)≡4(mod7)
a_(2k)≡2(mod7)
を使うといいと思う。