Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- #include <fstream>
- #include <string>
- #include <set>
- #include <vector>
- #define MOD 1000000007
- #define ll long long
- using namespace std;
- string add(string a, string b) {
- if(a.size() < b.size()) {
- swap(a, b);
- }
- int i = (int) a.size() - 1, j = (int) b.size() - 1;
- string res = "";
- int carry = 0;
- while(j >= 0) {
- int sum = (a[i] - '0') + (b[j] - '0') + carry;
- if(sum > 9) {
- sum -= 10;
- carry = 1;
- }
- else {
- carry = 0;
- }
- res += (sum + '0');
- i--;
- j--;
- }
- while(i >= 0) {
- int sum = (a[i] - '0') + carry;
- if(sum > 9) {
- sum -= 10;
- carry = 1;
- }
- else {
- carry = 0;
- }
- res += (sum + '0');
- i--;
- }
- if(carry == 1) {
- res += "1";
- }
- reverse(res.begin(), res.end());
- return res;
- }
- string multiply(string a, string b) {
- int sz_a = (int) a.size();
- int sz_b = (int) b.size();
- vector<int> v(sz_a + sz_b, 0);
- for(int i = sz_a - 1; i >= 0; i--){
- for(int j = sz_b - 1; j >= 0; j--) {
- v[i + j + 1] += (a[i] - '0') * (b[j] - '0');
- }
- }
- for(int i = sz_a + sz_b - 1; i >= 0; i--) {
- if(v[i] > 9) {
- v[i - 1] += v[i] / 10;
- v[i] %= 10;
- }
- }
- int i = 0;
- while(v[i] == 0) {
- i++;
- }
- string res = "";
- while(i < sz_a + sz_b) {
- res += (v[i] + '0');
- i++;
- }
- if(res == "") {
- res = "0";
- }
- return res;
- }
- int main() {
- int n;
- cin >> n;
- string sum = "0";
- string power_of_two = "1";
- for(int i = 0; i < n; i++) {
- power_of_two = multiply(power_of_two, "2");
- sum = add(sum, power_of_two);
- }
- cout << sum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement