When Python won C++

I recently started doing these code-chef practice questions and there was this question that particularly got my interest. It’s a simple question. It says for a number(n) entered you have to find it’s factorial(n!). Yeah! Pretty simple isn’t it. All you have to do is a loop from 1 to n multiplying each number to it’s previous one.

The Catch!

Your number can range from 1 <= n <= 100. Bam! C++ is not capable of storing long numbers like that. The long int in C++ can only hold up to 10 digits and in the worst case 100! will have 158 digits. Wow!

Python to the rescue. Python has something called a BigInteger which basically says it has no limit on the number of digits and can be as long as the system memory can support. And boom! storing large numbers isn’t a big deal anymore.

I feel it’s good to have a mix and match of languages while doing competitive programming. Kind of makes you realize why so many languages exists.

Categories: Uncategorized

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: