We present a new method to study the long term evolution of cometary nuclei in order to retrieve their original size. We considered the two cases of comet 46P/Wirtanen and 67P/Churyumov-Gerasimenko. We calculated the past evolution of the orbital elements of both comets over 100,000 years using a Bulirsch- Stoer integrator and over 450,000 years using a Radau integrator, that we combined with a realistic model for the erosion of the nucleus to estimate their original size. We derived that for the long term evolution of the orbital elements of a comet, the main effect is the chaos resulting from close encounters with planets, and this effect is dominant whatever the choice of the integrator or the presence or not of non-gravitational forc...