do not use recursive to solve the problem, I replace long with int, because we do not want to consider overflow now