Problem p00646 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge {
  int to, from, cost;
};

#ifdef DEBUG
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    debug << *i << " ";
  debug << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; i--)
#define repn(i, m, n) for (int i = (m); i <= (n); ++i)
#define repnd(i, m, n) for (int i = (n)-1; i >= (m); i--)
#define rep0(i, n) for (i = 0; i < (n); ++i)
#define all(n) n.begin(), n.end()
#define sz(n) ((int)(n).size())
#define IL for (;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug << "LINE:" << __LINE__ << endl;

const int INF = 2147483647 / 3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[] = {1, -1, 0, 0, 1, -1, 1, -1, 0};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1, 0};

vpint a;

int main() {
  Int n, m;
  IL {
    cin >> n;
    if (n == 0)
      break;
    if (n == 1) {
      cout << 1 << endl;
      continue;
    }
    m = n;
    a.clear();
    Int i;
    for (i = 2; i * i <= n; i = (i == 2) ? 3 : i + 2) {
      if (n % i == 0) {
        int c = 0;
        while (m % i == 0) {
          m /= i;
          ++c;
        }
        a.PB(MP((int)i, c));
      }
    }
    if (m == n) {
      cout << 2 << endl;
      continue;
    }
    if (m > 1) {
      a.PB(MP((int)m, 1));
    }
    Int res = 1;
    rep(i, sz(a)) { res *= a[i].second * 2 + 1; }
    res = res / 2 + 1;
    cout << res << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge {
  int to, from, cost;
};

#ifdef DEBUG
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    debug << *i << " ";
  debug << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; i--)
#define repn(i, m, n) for (int i = (m); i <= (n); ++i)
#define repnd(i, m, n) for (int i = (n)-1; i >= (m); i--)
#define rep0(i, n) for (i = 0; i < (n); ++i)
#define all(n) n.begin(), n.end()
#define sz(n) ((int)(n).size())
#define IL for (;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug << "LINE:" << __LINE__ << endl;

const int INF = 2147483647 / 3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[] = {1, -1, 0, 0, 1, -1, 1, -1, 0};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1, 0};

vpint a;

int main() {
  Int n, m;
  IL {
    cin >> n;
    if (n == 0)
      break;
    if (n == 1) {
      cout << 1 << endl;
      continue;
    }
    m = n;
    a.clear();
    Int i;
    for (i = 2; i * i <= n; ++i) {
      if (n % i == 0) {
        int c = 0;
        while (m % i == 0) {
          m /= i;
          ++c;
        }
        a.PB(MP((int)i, c));
      }
    }
    if (m > 1) {
      cout << 2 << endl;
      continue;
    }
    Int res = 1;
    rep(i, sz(a)) { res *= a[i].second * 2 + 1; }
    res = res / 2 + 1;
    cout << res << endl;
  }
  return 0;
}