Fermats theorem

its not workin a^(p-1)%p=1,
its working just in some cases and not in all