Added solution to P31 way too slow