ideone.com/mkJgh8
Read the problem statement carefully.
but i am not understanding how to put the constraint " For a given positive integer K of not more than 1000000 digits ".
It certainly doesn't fit in any of the numeric data types, that's for sure.