Problem p00836 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i))
#define rep(i, n) FOR(i, 0, n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template <class T> using vv = vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;

int main() {
  vi V;
  FOR(i, 2, 10001) { V.pb(i); }
  rep(i, V.size()) {
    int v = V.at(i);
    for (int j = V.size() - 1; j > i; j--) {
      if (V.at(j) % v == 0)
        V.erase(V.begin() + j);
    }
  }
  while (1) {
    int count = 0;
    int i = 0;
    queue<int> Q;
    int sum = 0;
    int A;
    cin >> A;
    if (A == 0) {
      break;
    }
    while (1) {
      if (sum == A) {
        count += 1;
        sum += V[i];
        Q.push(V[i++]);
      } else if (sum > A) {
        if (Q.size() == 1) {
          break;
        } else {
          sum -= Q.front();
          Q.pop();
        }
      } else {
        sum += V[i];
        Q.push(V[i++]);
      }
    }
    cout << count << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i))
#define rep(i, n) FOR(i, 0, n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template <class T> using vv = vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;

int main() {
  vi V;
  FOR(i, 2, 10008) { V.pb(i); }
  rep(i, V.size()) {
    int v = V.at(i);
    for (int j = V.size() - 1; j > i; j--) {
      if (V.at(j) % v == 0)
        V.erase(V.begin() + j);
    }
  }
  while (1) {
    int count = 0;
    int i = 0;
    queue<int> Q;
    int sum = 0;
    int A;
    cin >> A;
    if (A == 0) {
      break;
    }
    while (1) {
      if (sum == A) {
        count += 1;
        sum += V[i];
        Q.push(V[i++]);
      } else if (sum > A) {
        if (Q.size() == 1) {
          break;
        } else {
          sum -= Q.front();
          Q.pop();
        }
      } else {
        sum += V[i];
        Q.push(V[i++]);
      }
    }
    cout << count << endl;
  }
  return 0;
}