Problem p03359 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
typedef long long ll;
const double PI = 3.141592654;
#define rep(i, x) for (int(i) = 0; (i) < (ll)(x); (i)++)
#define all(s) (s).begin(), (s).end()
#define allv(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pb push_back
#define sz s.size()
#define ssz ss.size()
#define vz v.size()
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int dx[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dy[] = {1, -1, 0, 0, 1, 1, -1, -1};
// x = atoill(s.c_str())
void fast() {
#ifndef ONLINE_JUDGE
  /*

  **    ** ** **    *********   ** ** **
  **    **          **     **   **
  **    **          *********   **
  **    **          **          **
  **    ** ** **    **          ** ** **
  */
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
int main() {
  fast();
  int a, b, mo = 1, d = 1, c = 0;
  cin >> a >> b;
  while (1) {
    if (mo == a && d == b) {
      if (mo == d)
        c++;
      break;
    }
    if (d == 32)
      d = 0, mo++;
    if (mo == d)
      c++;
    d++;
  }
  cout << c;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
typedef long long ll;
const double PI = 3.141592654;
#define rep(i, x) for (int(i) = 0; (i) < (ll)(x); (i)++)
#define all(s) (s).begin(), (s).end()
#define allv(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pb push_back
#define sz s.size()
#define ssz ss.size()
#define vz v.size()
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int dx[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dy[] = {1, -1, 0, 0, 1, 1, -1, -1};
// x = atoill(s.c_str())
void fast() {
#ifndef ONLINE_JUDGE
  /*

  **    ** ** **    *********   ** ** **
  **    **          **     **   **
  **    **          *********   **
  **    **          **          **
  **    ** ** **    **          ** ** **
  */
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
int main() {
  fast();
  int a, b, mo = 1, d = 1, c = 0;
  cin >> a >> b;
  while (1) {
    if (mo == a && d == b) {
      if (mo == d)
        c++;
      break;
    }
    if (d == 32)
      d = 0, mo++;
    if (mo == d)
      c++;
    d++;
  }
  cout << c;
  return 0;
}