[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
create ints n and m
create bool array use with 20 elements
void function calc with int arguments len1, len2, cur, t and integer reference &ans
    if cur is equal to len1 + len2
        increment ans by one
    else if cur = len1
        loop i from 0 to 7 exclusive
            if use[i] is false and i < m
                set use[i] to 1
                call function calc with arguments len1, len2, cur + 1, i and ans
                set use[i] to 0
            end of the block
    else if cur is greater than len1
        loop i from 0 to 7 exclusive
            if use[i] is false and t * 7 + i < m
                set use[i] to 1
                call calc with arguments len1, len2, cur + 1, t * 7 + i and ans
                set use[i] to 0
            end of the block
    else
        loop i from 0 to 7 exclusive
            if use[i] is false and t * 7 + i < n
                change use[i] to 1
                call calc with arguments len1, len2, cur + 1, t * 7 + i and ans
                change use[i] to 0
            end of the block
    end of the block
end of the block
define the main function
    read n and m
    create integers len1 and len2 = 0, N = n and M = m, then decrement n and m
    while n is not 0
        increment len1 by one
        divide n by 7
    end of the block
    while m is not 0
        increment len2 by one
        divide m by 7
    end of the block
    set len1 to max of len1 and 1
    set len2 to max of len2 and 1
    assign N to n and M to m
    if len1 + len2 is greater than 7
        print 0
    else
        set value of sizeof(use) bytes at the pointer use to 0
        create integer ans = 0
        call calc with arguments len1, len2, 0, 0 and ans
        print ans
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int n, m;
bool use[20];
void calc(int len1, int len2, int cur, int t, int &ans) {
    if (cur == len1 + len2)
        ans++;
    else if (cur == len1) {
        for (int i = 0; i < 7; i++)
            if (!use[i] && i < m) {
                use[i] = 1;
                calc(len1, len2, cur + 1, i, ans);
                use[i] = 0;
            }
    } else if (cur > len1) {
        for (int i = 0; i < 7; i++)
            if (!use[i] && t * 7 + i < m) {
                use[i] = 1;
                calc(len1, len2, cur + 1, t * 7 + i, ans);
                use[i] = 0;
            }
    } else {
        for (int i = 0; i < 7; i++)
            if (!use[i] && t * 7 + i < n) {
                use[i] = 1;
                calc(len1, len2, cur + 1, t * 7 + i, ans);
                use[i] = 0;
            }
    }
}
int main() {
    cin >> n >> m;
    int len1 = 0, len2 = 0, N = n--, M = m--;
    while (n) {
        len1++;
        n /= 7;
    }
    while (m) {
        len2++;
        m /= 7;
    }
    len1 = max(len1, 1);
    len2 = max(len2, 1);
    n = N, m = M;
    if (len1 + len2 > 7)
        cout << 0 << endl;
    else {
        memset(use, 0, sizeof(use));
        int ans = 0;
        calc(len1, len2, 0, 0, ans);
        cout << ans << endl;
    }
    return 0;
}