solution without obtaining factorization
solution solving prime factorization