tried a different way. Brute force hangs on larger number