Saturday 17 August 2013

calculating 2^1000 without any module/library

calculating 2^1000 without any module/library

i am practicing on projecteuler and am working on a problem to calculate
2**1000(2^1000) in python. my code is
z=2**1000
sum=0
while z>0:
x=int(z%10)
sum+=x
z=z/10
print(sum)
gives result
10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
1189
while python is able to calculate right value for z but why is the sum not
correct? (PS.don't need one line solutions)

No comments:

Post a Comment