Solution (source code)

= Solution

For $b>1$, <Euler's theorem> allows $d=\varphi(b)>0$, since $a,b$ are <coprime integers>. At $b=1$ every congruence holds and one may take $d=1$. Let $y$ be the <multiplicative order> of $a$ modulo $b$. Write a nonnegative exponent $x=qy+r$ with $0\le r<y$ using the <Euclidean division>. Then $a^x\equiv a^r\pmod b$, so $a^x\equiv1$ implies $r=0$ by minimality of $y$. Thus $y\mid x$. Negative exponents, if included, give the same conclusion using the inverse residue of $a$.

A <prime divisor of a Fermat number> $F_n=2^{2^n}+1$ is odd, and satisfies $2^{2^n}\equiv-1\pmod p$. Therefore $2^{2^{n+1}}\equiv1\pmod p$, so its <multiplicative order> divides $2^{n+1}$. It does not divide $2^n$, since $-1\ne1$ modulo the odd prime. Every divisor of $2^{n+1}$ is a power of two, hence
$$
\boxed{\operatorname{ord}_p(2)=2^{n+1}}.
$$
By <Fermat's little theorem> and the divisibility just proved, $2^{n+1}\mid p-1$, giving $\boxed{p\equiv1\pmod{2^{n+1}}}$.