Finding square root through prime factorisation