php has a slow powmod function for some reason