Note :This post is first published on Apr-2013 in my previous blog Techkindle. Moving the content here.

Below code, without using BigInteger structure.

Output

Happy Learning 🙂