Skip to content

Instantly share code, notes, and snippets.

@srinathgs
Created August 6, 2012 09:37
Show Gist options
  • Select an option

  • Save srinathgs/3272742 to your computer and use it in GitHub Desktop.

Select an option

Save srinathgs/3272742 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> digits;
int carry;
digits.push_back(1);
//Just Old School Multiplication.
for(int i = 1;i<=1000;i++){
carry = 0;
for(vector<int>::iterator i = digits.begin();i != digits.end();i++){
*i = *i*2 + carry;
if(*i > (9) && ((i+1)!= digits.end())){
*i = *i - 10;
carry = 1;
}
else if(*i>(9) && ((i+1)==digits.end())){
*i = *i - 10;
digits.push_back(1);
break;
}
else if(*i<=9){
carry = 0;
}
}
}
int sum = 0;
for(vector<int>::iterator j = digits.begin(); j!=digits.end();j++){
sum+=*j;
}
cout<<sum<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment