Works for a and p where a < p. Composite numbers are next