Hello , Most of us might solve www.projecteuler.net Problems So Here With Problem 16 that asks to Sum the Digits of 2^1000
I made it but I feel that I am making it too hard for me :)
So here is my Code & Tell me ur opinions , Easier Methods , etc...
Thanks in advance ....
PS : Please Don;t Tell me about Code Organizing Bcuz I'am bad at that
your right. formatting is VERY important. please work on that. also there is a pattern you are missing that could make this alot easier. think of the values of the sum as get power gets higher.
Well you do realize there is a pattern in which powers of 2 go up. There are patterns for all exponential equations like this. Graph 2^x And it becomes more apparent
I know he is counting the digits but there is still a pattern to how the numbers add up.
I have no idea if this continues indefinitely (requires a maths proof) but, if it does, we have that:
sumdigit(2^n) =
2 if n is of the form 6k-5
4 if n is of the form 6k-4
8 if n is of the form 6k-3
7 if n is of the form 6k-2
5 if n is of the form 6k-1
1 if n is of the form 6k
1000=6k-2 gives k=167 (all the others give fractional values for k).
Hence the sum of the digits is 7.
P.S: You can adapt the sumdigit part of this for mods. This just gives a program with lots of if(power%6)=this then output that etc.
>JLBorges In fact I have just read the tutorial here & I am currently reading C++ Primer by Lippman , but my exams (I study Some damn stupid stuff) are eating up my time :)
So I have on my to read list
1- The rest of C++ Primer by Lippman
2- The C++ Standard Library - A Tutorial and Reference by Nicolai