Lemma. For any integer p≥2, if c−1≡2p(mod2p+1), then c2−1≡2p+1(mod2p+2).
*Proof.* Write c2−1=(c−1)(c+1). By hypothesis, c−1 is divisible by 2p. As c+1 leaves remainder 2 upon division by 2p, it follows that 2p+1 is the highest power of 2 dividing c2−1, whence the conclusion of the lemma.
Let 2α and 2β be the highest powers of 2 dividing a−1 and b−1, respectively. By hypothesis, α≥2 and β≥2. Note that a−1≡2α(mod2α+1) and b−1≡2β(mod2β+1). We may and will assume α≤β. Apply the lemma β−α times to get a2β−α−1(mod2β+1)=2β, so a2β−α−b=(a2β−α−1)−(b−1) is divisible by 2β+1.
Now, induct on n. By the preceding, if n≤β+1, then a2β−α−b is divisible by 2n, so k=2β−α will do. Let n>β.
For the induction step, let ak−b be divisible by 2n for some k≥1. If it is divisible by 2n+1 we are done, so let ak−b≡2n(mod2n+1).
*Second solution.* Clearly, k=1 works for both n=1 and n=2, so let n≥3. If a=1 or b=1, the conclusion follows by Euler's theorem, so let a≥5 and b≥5. Note that a and b may be replaced by their residues modulo 2n to assume them both less than 2n.
For every integer 2≤m<n, let Sm={2mu+1:u=0,…,2n−m−1}. We first show that if x and y are in Sm, then so is xy(mod2n). Write x=2mu+1 and y=2mv+1. Then xy=2mv+1, where w=2muv+u+v. Note that w0=w(mod2n−m) falls in the range 0 through 2n−m−1 and write w=2n−mw′+w0. Then xy=2m(2n−mw′+w0)+1=2nv+2mw0+1, where 2mw0+1<2n. Consequently, xy(mod2n)=2mv+1 is in Sm, as stated.
Let 2α and 2β be the highest powers of 2 dividing a−1 and b−1, respectively. We may and will assume α≤β. Note that a=2αu+1 belongs to Sα, where u is odd and 2≤α≤n−1. By the preceding, the residues modulo 2n of a,a2,a3,…,a2n−α are all in Sα.
We now show that 2n−α is the least positive integer s satisfying as≡1(mod2n). By minimality, s divides 2n−1, as a2n−1≡1(mod2n). Write
a2n−α−1=(a−1)(a+1)(a2+1)⋯(a2n−α−1+1).
As 2α divides a−1 and 2n−α divides (a+1)(a2+1)⋯(a2n−α−1+1), it follows that 2n divides a2n−α−1, so a2n−α≡1(mod2n).
Suppose now, if possible, that s divides 2n−α−1. Then a2n−α−1≡1(mod2n), so 2n divides (a−1)(a+1)(a2+1)⋯(a2n−α−2+1). As (a+1)(a2+1)⋯(a2n−α−2+1) is divisible by 2n−α−1 but not by 2n−α, it follows that a−1 is divisible by 2α+1, contradicting the choice of α. Consequently, s=2n−α, as stated.
Third solution. Work in Z2n. Clearly, k=1 works for both n=1 and n=2, so let n≥3. The units of Z2n consist of all positive odd integers less than 2n. They form a multiplicative copy of the additive Z2n−2×Z2 with generators 5, of order 2n−2, and 2n−1, of order 2. Thus every unit has the form 5γ(2n−1)ϵ, γ=0,1,…,2n−2−1, ϵ=0,1.
As a and b are both 1 modulo 4, it follows that a=5α and b=5β. As 5 has order 2n−2, it is sufficient to provide a positive integer k such that at least one of the numbers αk−β and βk−α is divisible by 2n−2.
Let 2m be the highest power of 2 dividing gcd(α,β). Then at least one of the numbers α/2m and β/2m is odd and hence invertible modulo 2n−2; say, α/2m is odd and let α′ be its inverse modulo 2n−2. Then k=α′β/2m makes αk−β divisible by 2n−2, as desired.