Again, python has proved to me that it can beat C in many aspects!! I learned yesterday that it stores the integers without worrying about the overflowing. It keeps on increasing the memory for larger numbers, isn’t it amazing? I thought of giving a try to see upto what it can store and I wrote a simple script which keeps on doing the power of two, and it went on and on and on and never came out!! I was really impresses. The reason being help that I would get with such a liberty to solve the project euler problems :)

One of the problem I solved using python was sigma(i^i), where i ranges from 1 to 1000. and I was supposed to print the last 10 digits of the answer. I cannot think of solving this problem using C. I wonder how will I manage to store such a data. Using unsigned long long, I can store maximum 20 digit number :) Can’t imaging how big the number will be after the summation. So the choice was obviously python, and here is the code :)

#!/usr/bin/python
# Solution to Problem 48 in projecteuler.net
ans = 0;
limit = 1000;
for i in range(1,limit):
ans = ans + pow(i,i)
print str(ans)[-10:]

0.000000
0.000000

### Like this:

Like Loading...

*Related*