Fermat's theorem

Hey! I don’t understand the theorem…

Why did he write A^B as A ^ (a ( p-1) +b)??

And also b as B%(p-1)?