0 = pow(2,0) - 1, %3 = 0

1 = pow(2,1) -1, %3 = 1

3 = pow(2,2) - 1, %3 = 0

7 = pow(2,3) -1, %3 = 1

...

for n=0 and 1:

we know 2*pow(4,n) -1 = N*3 +1

we get 2*pow(4,n) = N*3 +2

so when n becomes n+1:

2*pow(4,n+1) -1 = 4*(N*3 +2) -1 = 12*N +7, which %3 = 1

Similarly,

for n=0 and 1:

we know pow(4,n) -1 = N*3

when n becomes n+1:

pow(4, n+1) - 1 = 12*N-1+1 which %3 = 0