How to solve hdu2647 problem using N! again?