I am trying to compute [(2 ^ (2*n-1) + 1) / 3] mod m. The value for n can be very large, so computations are performed mod m.
The computed value is always an integer, and hence the computation is valid for all m.
When m is not divisible by 3, we can use mod power to compute the power of 2, add 1, then multiply by the mod inverse of 3.
However, I am stuck when m is divisible by 3. How do we perform the computation when m is divisible by 3?