Advertisement
TwITe

Untitled

Jan 29th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define ull unsigned long long
  6.  
  7. const int base = 10;
  8.  
  9. void solve() {
  10.     string s;
  11.     int n;
  12.     cin >> n;
  13.     vector<int> a;
  14.     s = "1";
  15.  
  16.     //--------
  17.     //read long num
  18.     for (int i = s.size() - 1; i >= 0; i--) {
  19.         a.push_back(s[i] - '0');
  20.     }
  21.  
  22.     //multiplication
  23.     for (int j = 0; j < n; j++) {
  24.         int carry = 0;
  25.         for (int i = 0; i < a.size() || carry; i++) {
  26.             if (i == a.size()) {
  27.                 a.push_back(0);
  28.             }
  29.             int cur = a[i] * 2 + carry;
  30.             a[i] = cur % base;
  31.             carry = cur / base;
  32.         }
  33.     }
  34.  
  35.     //print num
  36.     for (int i = a.size() - 1; i >= 0; i--) {
  37.         cout << a[i];
  38.     }
  39.  
  40.     cout << endl;
  41. }
  42.  
  43.  
  44. int main() {
  45.     solve();
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement