solve Euler problem for NxN case.