use unsigned int as the int is not sufficient for a very large limiting case. still time limit exceeded...! needs improvement