func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, sz;   int par[4000005];   int findpar(int x) {     if (par[x] == x) return par[x];     par[x] = findpar(par[x]);     return par[x];   }   int cr, cc;   int pr, pc;   void decode(int x) {     if (x < m) {       cr = 0;       cc = x;     } else if (x < m + n - 1) {       cr = x - m + 1;       cc = m - 1;     } else if (x < 2 * m + n - 2) {       cr = n - 1;       cc = m - 1 - (x - (m + n - 2));     } else {       cr = n - 1 - (x - (2 * m + n - 3));       cc = 0;     }   }   int encode(int r, int c) {     if (r == 0) return c;     if (c == m - 1) return m - 1 + r;     if (r == n - 1) return m + n - 2 + m - 1 - c;     if (c == 0) return 2 * m + n - 3 + n - 1 - r;   }   bool inrange(int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; }   void go(int r, int c, int dr, int dc) {     int x;     if (dr == -1 && dc == -1) x = min(r, c);     if (dr == -1 && dc == 1) x = min(r, m - 1 - c);     if (dr == 1 && dc == -1) x = min(n - 1 - r, c);     if (dr == 1 && dc == 1) x = min(n - 1 - r, m - 1 - c);     pr = r + x * dr;     pc = c + x * dc;   }   int main() {     cin >> n >> m;     sz = 2 * (n + m) - 4;     for (int i = 0; i < sz; ++i) par[i] = i;     for (int i = 0; i < sz; ++i) {       decode(i);       for (int dr = -1; dr <= 1; dr += 2)         for (int dc = -1; dc <= 1; dc += 2) {           if (inrange(cr + dr, cc + dc)) {             go(cr, cc, dr, dc);             int x = encode(pr, pc);             int px = findpar(x);             int pi = findpar(i);             if (px != pi) {               par[max(pi, px)] = min(pi, px);             }           }         }     }     set<int> st;     for (int i = 0; i < sz; ++i) st.insert(findpar(i));     cout << st.size() << endl;     return 0;   }   