Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #define THING 450
- #define POWERTO 1000
- #define BASE 2
- int main()
- {
- unsigned short sum = 0, curPower = 0, t_index = 0, carry = 0;
- unsigned short *total = new unsigned short[THING]; //Wasteful? Probably.
- if(!total) return 1;
- memset(total, 0, THING*sizeof(unsigned short)); //Make sure all that fancy new memory we have is nice and clean
- total[0] = 1; //Lazy way to emulate 2^0
- while(curPower < POWERTO)
- {
- for(t_index = 0; t_index < THING; t_index++) total[t_index] *= BASE; //Multiply everything by the BASE
- for(t_index = 0; t_index < THING; t_index++)
- {
- if(total[t_index] > 9) //Handle all the carries
- {
- carry = total[t_index] / 10;
- total[t_index] %= 10;
- total[t_index + 1] += carry;
- }
- }
- curPower++; //Do it again
- }
- for(t_index = 0; t_index < THING; t_index++) sum += total[t_index]; //Add the numbers together
- std::cout << "Sum = " << sum << std::endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment