Guest User

Untitled

a guest
May 20th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. #define THING 450
  5. #define POWERTO 1000
  6. #define BASE 2
  7.  
  8. int main()
  9. {
  10.     unsigned short sum = 0, curPower = 0, t_index = 0, carry = 0;
  11.     unsigned short *total = new unsigned short[THING];  //Wasteful?  Probably.
  12.  
  13.     if(!total)  return 1;
  14.  
  15.     memset(total, 0, THING*sizeof(unsigned short)); //Make sure all that fancy new memory we have is nice and clean
  16.  
  17.     total[0] = 1;   //Lazy way to emulate 2^0
  18.  
  19.     while(curPower < POWERTO)
  20.     {
  21.         for(t_index = 0; t_index < THING; t_index++)    total[t_index] *= BASE; //Multiply everything by the BASE
  22.  
  23.         for(t_index = 0; t_index < THING; t_index++)
  24.         {
  25.             if(total[t_index] > 9)  //Handle all the carries
  26.             {
  27.                 carry = total[t_index] / 10;
  28.                 total[t_index] %= 10;
  29.                 total[t_index + 1] += carry;
  30.             }
  31.         }
  32.         curPower++; //Do it again
  33.     }
  34.    
  35.     for(t_index = 0; t_index < THING; t_index++)    sum += total[t_index];  //Add the numbers together
  36.  
  37.     std::cout << "Sum = " << sum << std::endl;  
  38.  
  39.     return 0;
  40. }
Add Comment
Please, Sign In to add comment