Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i, n) for (int i = (int)0; i < (int)n; i++)
#define llrep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define REP(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define all(var) (var).begin(), (var).end()
#define prt(var) cout << var << endl
#define prt_dbl(i, var) cout << fixed << setprecision(i) << var << endl;
template <typename Val> Val gcd(Val a, Val b) {
  // use ll or int for gcd
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <typename Val> Val vec_max(vector<Val> v) {
  return *max_element(v.begin(), v.end());
}
template <typename Val> Val vec_min(vector<Val> v) {
  return *min_element(v.begin(), v.end());
}
template <typename Val> void show_vec(vector<Val> *v) {
  cout << endl;
  rep(i, v->size()) { cout << v->at(i) << " "; }
  cout << endl;
}

template <typename Val, typename Number>
void count_vector(vector<Val> *A, vector<pair<Number, Val>> *R) {
  sort(A->begin(), A->end());
  int count = 1;
  rep(i, A->size()) {
    if (i < A->size() - 1) {
      if (A->at(i) == A->at(i + 1))
        count++;
      else {
        R->emplace_back(count, A->at(i));
        count = 1;
      }
    } else {
      R->emplace_back(count, A->at(i));
    }
  }
}

//---------------------------------------------------------------
int main() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> F;
  llrep(i, N / 2) {
    ll I = i + 1;
    if (N % I == 0) {
      F.emplace_back(I, N / I);
    }
  }
  ll ans = to_string(N).size();
  llrep(i, F.size()) {
    ll A, B;
    A = to_string(F.at(i).first).size();
    B = to_string(F.at(i).second).size();
    if (max(A, B) < ans) {
      ans = max(A, B);
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i, n) for (int i = (int)0; i < (int)n; i++)
#define llrep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define REP(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define all(var) (var).begin(), (var).end()
#define prt(var) cout << var << endl
#define prt_dbl(i, var) cout << fixed << setprecision(i) << var << endl;
template <typename Val> Val gcd(Val a, Val b) {
  // use ll or int for gcd
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <typename Val> Val vec_max(vector<Val> v) {
  return *max_element(v.begin(), v.end());
}
template <typename Val> Val vec_min(vector<Val> v) {
  return *min_element(v.begin(), v.end());
}
template <typename Val> void show_vec(vector<Val> *v) {
  cout << endl;
  rep(i, v->size()) { cout << v->at(i) << " "; }
  cout << endl;
}

template <typename Val, typename Number>
void count_vector(vector<Val> *A, vector<pair<Number, Val>> *R) {
  sort(A->begin(), A->end());
  int count = 1;
  rep(i, A->size()) {
    if (i < A->size() - 1) {
      if (A->at(i) == A->at(i + 1))
        count++;
      else {
        R->emplace_back(count, A->at(i));
        count = 1;
      }
    } else {
      R->emplace_back(count, A->at(i));
    }
  }
}

//---------------------------------------------------------------
int main() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> F;
  llrep(i, sqrt(N)) {
    ll I = i + 1;
    if (N % I == 0) {
      F.emplace_back(I, N / I);
    }
  }
  ll ans = to_string(N).size();
  llrep(i, F.size()) {
    ll A, B;
    A = to_string(F.at(i).first).size();
    B = to_string(F.at(i).second).size();
    if (max(A, B) < ans) {
      ans = max(A, B);
    }
  }

  cout << ans << endl;
}