prithivMLmods/Coder-Stat huggingface dataset:
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long n, m;
  cin >> n >> m;
  vector<pair<int, int>> student(n, pair<int, int>());
  vector<pair<int, int>> checkpoint(n, pair<int, int>());
  for (int i = 0; i < n; i++)
    cin >> student[i].first >> student[i].second;
  for (int i = 0; i < m; i++)
    cin >> checkpoint[i].first >> checkpoint[i].second;

  for (int i = 0; i < n; i++) {
    long ans;
    long min_distance = 99999999999;
    for (int j = 0; j < m; j++) {
      long distance;
      if (student[i].first >= checkpoint[j].first)
        distance = student[i].first - checkpoint[j].first;
      else
        distance = checkpoint[j].first - student[i].first;
      if (student[i].second >= checkpoint[j].second)
        distance += student[i].second - checkpoint[j].second;
      else
        distance += checkpoint[j].second - student[i].second;
      if (distance < min_distance) {
        min_distance = distance;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}

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

int main() {
  long n, m;
  cin >> n >> m;
  vector<pair<int, int>> student(n, pair<int, int>());
  vector<pair<int, int>> checkpoint(m, pair<int, int>());
  for (int i = 0; i < n; i++)
    cin >> student[i].first >> student[i].second;
  for (int i = 0; i < m; i++)
    cin >> checkpoint[i].first >> checkpoint[i].second;

  for (int i = 0; i < n; i++) {
    long ans;
    long min_distance = 99999999999;
    for (int j = 0; j < m; j++) {
      long distance;
      if (student[i].first >= checkpoint[j].first)
        distance = student[i].first - checkpoint[j].first;
      else
        distance = checkpoint[j].first - student[i].first;
      if (student[i].second >= checkpoint[j].second)
        distance += student[i].second - checkpoint[j].second;
      else
        distance += checkpoint[j].second - student[i].second;
      if (distance < min_distance) {
        min_distance = distance;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
/* コードこちらに */
#include <bits/stdc++.h> //1
using namespace std;     // 2
int solve() {            // 3
} // 4
int main() {                             // 5
  int n, m;                              // 7
  cin >> n >> m;                         // 8
  vector<pair<long long, long long>> ab; // 1
  vector<pair<long long, long long>> cd; // 2
  for (int i = 0; i < n; ++i) {          // 3
    cin >> ab[i].first >> ab[i].second;  // 4 これあってるのか？
  }                                      // 5 あってるきがします…！
  for (int i = 0; i < m; ++i) {          // 7
    cin >> cd[i].first >> cd[i].second;  // 8
  }                                      // 1
  for (int i = 0; i < n; ++i) {          // 2
    int ans = -1, dist = 1e8;            // 3
    for (int j = 0; j < m; j++) {        // 4
      if (abs(ab[i].first - cd[j].first) + abs(ab[i].second - cd[j].second) <
          dist) { // 5
        ans = j, dist = abs(ab[i].first - cd[j].first) +
                        abs(ab[i].second - cd[j].second); // 7
      }                                                   // 8 ifの}
    }                                                     // 1 ひゃ
    cout << ans + 1 << endl;                              // 2　
    if ("true" == "true") {                               // 3
    }                                                     // 4 こらこら
  }                                                       // 5
} // 7 end

Fixed submission:
/* コードこちらに */
#include <bits/stdc++.h> //1
using namespace std;     // 2
int solve() {            // 3
} // 4
int main() {                                // 5
  int n, m;                                 // 7
  cin >> n >> m;                            // 8
  vector<pair<long long, long long>> ab(n); // 1
  vector<pair<long long, long long>> cd(m); // 2
  for (int i = 0; i < n; ++i) {             // 3
    cin >> ab[i].first >> ab[i].second;     // 4 これあってるのか？
  }                                     // 5 あってるきがします…！
  for (int i = 0; i < m; ++i) {         // 7
    cin >> cd[i].first >> cd[i].second; // 8
  }                                     // 1
  for (int i = 0; i < n; ++i) {         // 2
    int ans = -1, dist = 1e9;           // 3
    for (int j = 0; j < m; j++) {       // 4
      if (abs(ab[i].first - cd[j].first) + abs(ab[i].second - cd[j].second) <
          dist) { // 5
        ans = j, dist = abs(ab[i].first - cd[j].first) +
                        abs(ab[i].second - cd[j].second); // 7
      }                                                   // 8 ifの}
    }                                                     // 1 ひゃ
    cout << ans + 1 << endl;                              // 2　
    if ("true" == "true") {                               // 3
    }                                                     // 4 こらこら
  }                                                       // 5
} // 7 end
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  vector<int> C(N);
  vector<int> D(N);
  for (int i = 0; i < M; i++) {
    cin >> C[i] >> D[i];
  }
  vector<int64_t> p(N);
  vector<int64_t> md(N, 4000000000);

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (md[i] > abs(C[j] - A[i]) + abs(D[j] - B[i])) {
        p[i] = j + 1;
        md[i] = abs(C[j] - A[i]) + abs(D[j] - B[i]);
      }
    }
    cout << p[i] << endl;
  }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  vector<int> C(M);
  vector<int> D(M);
  for (int i = 0; i < M; i++) {
    cin >> C[i] >> D[i];
  }
  vector<int64_t> p(N);
  vector<int64_t> md(N, 4000000000);

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (md[i] > abs(C[j] - A[i]) + abs(D[j] - B[i])) {
        p[i] = j + 1;
        md[i] = abs(C[j] - A[i]) + abs(D[j] - B[i]);
      }
    }
    cout << p[i] << endl;
  }
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

long iabs(long a) {
  if (a < 0) {
    return -a;
  } else {
    return a;
  }
}

int main() {
  int N, M;

  cin >> N >> M;

  long a[N], b[N], c[N], d[N];
  long distance, dmin;
  int ans[N];

  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      distance = iabs(a[i] - c[j]) + iabs(b[i] - d[j]);
      if (j == 0) {
        dmin = distance;
        ans[i] = j;
      } else if (dmin > distance) {
        dmin = distance;
        ans[i] = j;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    cout << ans[i] + 1 << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

long iabs(long a) {
  if (a < 0) {
    return -a;
  } else {
    return a;
  }
}

int main() {
  int N, M;

  cin >> N >> M;

  long a[N], b[N], c[M], d[M];
  long distance, dmin;
  int ans[N];

  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      distance = iabs(a[i] - c[j]) + iabs(b[i] - d[j]);
      if (j == 0) {
        dmin = distance;
        ans[i] = j;
      } else if (dmin > distance) {
        dmin = distance;
        ans[i] = j;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    cout << ans[i] + 1 << endl;
  }

  return 0;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(n);
  vector<ll> d(n);

  rep(i, n) cin >> a.at(i) >> b.at(i);
  rep(i, m) cin >> c.at(i) >> d.at(i);
  map<int, ll> mp;

  rep(i, n) {
    ll dis = 1e9;
    rep(j, m) {
      ll temp = abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j));
      dis = min(dis, temp);
    }
    mp[i] = dis;
  }

  rep(i, n) {
    rep(j, m) {
      if (abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j)) == mp[i]) {
        cout << j + 1 << endl;
        break;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(m);
  vector<ll> d(m);

  rep(i, n) cin >> a.at(i) >> b.at(i);
  rep(i, m) cin >> c.at(i) >> d.at(i);
  map<int, ll> mp;

  rep(i, n) {
    ll dis = 1e9;
    rep(j, m) {
      ll temp = abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j));
      dis = min(dis, temp);
    }
    mp[i] = dis;
  }

  rep(i, n) {
    rep(j, m) {
      if (abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j)) == mp[i]) {
        cout << j + 1 << endl;
        break;
      }
    }
  }
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
// header {{{
#include <bits/stdc++.h>
using namespace std;

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF INT_MAX / 3
#define LLINF LLONG_MAX / 3
#define MOD (1000000007LL)
#define MODA(a, b) a = ((a) + (b)) % MOD
#define MODP(a, b) a = ((a) * (b)) % MOD
#define inc(i, l, r) for (int i = (l); i < (r); i++)
#define dec(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define pb push_back
#define se second
#define fi first
#define mset(a, b) memset(a, b, sizeof(a))

using LL = long long;
using G = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(n), d(n);
  inc(i, 0, n) cin >> a[i] >> b[i];
  inc(i, 0, m) cin >> c[i] >> d[i];

  inc(i, 0, n) {
    int min = INT_MAX;
    int ans = 0;
    inc(j, 0, m) {
      if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < min) {
        ans = j;
        min = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      }
    }
    cout << ans + 1 << endl;
  }
  return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF INT_MAX / 3
#define LLINF LLONG_MAX / 3
#define MOD (1000000007LL)
#define MODA(a, b) a = ((a) + (b)) % MOD
#define MODP(a, b) a = ((a) * (b)) % MOD
#define inc(i, l, r) for (int i = (l); i < (r); i++)
#define dec(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define pb push_back
#define se second
#define fi first
#define mset(a, b) memset(a, b, sizeof(a))

using LL = long long;
using G = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m);
  inc(i, 0, n) cin >> a[i] >> b[i];
  inc(i, 0, m) cin >> c[i] >> d[i];

  inc(i, 0, n) {
    int min = INT_MAX;
    int ans = 0;
    inc(j, 0, m) {
      if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < min) {
        ans = j;
        min = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      }
    }
    cout << ans + 1 << endl;
  }
  return 0;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;

int md(int a, int b, int c, int d) { return abs(a - c) + abs(b - d); }

int main() {
  int N, M;
  cin >> N >> M;
  vi a(N), b(N);
  rep(i, N) cin >> a.at(i) >> b.at(i);
  vi c(N), d(N);
  rep(i, M) cin >> c.at(i) >> d.at(i);

  rep(i, N) {
    vector<pii> p(M);
    rep(j, M) {
      p.at(j) = make_pair(md(a.at(i), b.at(i), c.at(j), d.at(j)), j + 1);
    }
    sort(all(p));
    cout << p.at(0).second << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;

int md(int a, int b, int c, int d) { return abs(a - c) + abs(b - d); }

int main() {
  int N, M;
  cin >> N >> M;
  vi a(N), b(N);
  rep(i, N) cin >> a.at(i) >> b.at(i);
  vi c(M), d(M);
  rep(i, M) cin >> c.at(i) >> d.at(i);

  rep(i, N) {
    vector<pii> p(M);
    rep(j, M) {
      p.at(j) = make_pair(md(a.at(i), b.at(i), c.at(j), d.at(j)), j + 1);
    }
    sort(all(p));
    cout << p.at(0).second << endl;
  }
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> vecA(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> vecA.at(i).at(j);
    }
  }

  vector<vector<int>> vecB(M, vector<int>(2));
  for (int k = 0; k < N; k++) {
    for (int l = 0; l < 2; l++) {
      cin >> vecB.at(k).at(l);
    }
  }

  for (int m = 0; m < N; m++) {
    long ans = 10000000000;
    int abs_x = 0;
    int ans_x = 0;
    for (int n = 0; n < M; n++) {
      abs_x = abs(vecA.at(m).at(0) - vecB.at(n).at(0)) +
              abs(vecA.at(m).at(1) - vecB.at(n).at(1));
      if (ans > abs_x) {
        ans = abs_x;
        ans_x = n + 1;
      }
    }
    cout << ans_x << endl;
  }
}

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

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> vecA(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> vecA.at(i).at(j);
    }
  }

  vector<vector<int>> vecB(M, vector<int>(2));
  for (int k = 0; k < M; k++) {
    for (int l = 0; l < 2; l++) {
      cin >> vecB.at(k).at(l);
    }
  }

  for (int m = 0; m < N; m++) {
    long ans = 10000000000;
    int abs_x = 0;
    int ans_x = 0;
    for (int n = 0; n < M; n++) {
      abs_x = abs(vecA.at(m).at(0) - vecB.at(n).at(0)) +
              abs(vecA.at(m).at(1) - vecB.at(n).at(1));
      if (ans > abs_x) {
        ans = abs_x;
        ans_x = n + 1;
      }
    }
    cout << ans_x << endl;
  }
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }
  for (int i = 0; i < n; i++) {
    long long mn = 1000000000000;
    int cou;
    for (int j = 0; j < m; j++) {
      if (mn > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
        mn = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        cou = j + 1;
      }
    }
    cout << cou << endl;
  }
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[n], c[m], d[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }
  for (int i = 0; i < n; i++) {
    long long mn = 1000000000000;
    int cou;
    for (int j = 0; j < m; j++) {
      if (mn > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
        mn = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        cou = j + 1;
      }
    }
    cout << cou << endl;
  }
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template <class t, class u> void chmax(t &a, u b) {
  if (a < b)
    a = b;
}
template <class t, class u> void chmin(t &a, u b) {
  if (b < a)
    a = b;
}
template <class t> using vc = vector<t>;
template <class t> using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
int SIZE(string s) { return (int)s.size(); }
const long long INF = 1LL << 60;

int main() {
  cout << fixed << setprecision(20);
  int n, m;
  cin >> n >> m;
  vc<pi> a(n), b(n);
  rep(i, n) cin >> a[i].first >> a[i].second;
  rep(i, m) cin >> b[i].first >> b[i].second;
  rep(i, n) {
    ll mi = INF;
    int ans = 0;
    rep(j, m) {
      ll cur = abs(a[i].first - b[j].first) + abs(a[i].second - b[j].second);
      if (cur < mi) {
        mi = cur;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template <class t, class u> void chmax(t &a, u b) {
  if (a < b)
    a = b;
}
template <class t, class u> void chmin(t &a, u b) {
  if (b < a)
    a = b;
}
template <class t> using vc = vector<t>;
template <class t> using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
int SIZE(string s) { return (int)s.size(); }
const long long INF = 1LL << 60;

int main() {
  cout << fixed << setprecision(20);
  int n, m;
  cin >> n >> m;
  vc<pi> a(n), b(m);
  rep(i, n) cin >> a[i].first >> a[i].second;
  rep(i, m) cin >> b[i].first >> b[i].second;
  rep(i, n) {
    ll mi = INF;
    int ans = 0;
    rep(j, m) {
      ll cur = abs(a[i].first - b[j].first) + abs(a[i].second - b[j].second);
      if (cur < mi) {
        mi = cur;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  int64_t z = 0;
  int64_t x = sqrt(n) / 1;
  for (int i = 0; i < x; i++) {
    if (n % (x - i) == 0) {
      z += n / (x - i);
      break;
    }
  }
  int count = 0;
  while (z > 0) {
    z / 10;
    count++;
  }
  cout << count;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  int64_t z = 0;
  int64_t x = sqrt(n) / 1;
  for (int i = 0; i < x; i++) {
    if (n % (x - i) == 0) {
      z += n / (x - i);
      break;
    }
  }
  string s = to_string(z);
  cout << s.size();
}
Problem p03775 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <fstream>
#include <iostream>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

ll mod(ll a, ll b) {
  ll ret = a % b;
  if (ret < 0)
    ret += b;
  return ret;
}

ll modpow(ll a, ll b, ll c) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = mod(res * a, c);
    a = mod(a * a, c);
    b >>= 1;
  }
  return res;
}

ll digitcal(ll x) {
  ll n = 0;
  while (x > 0) {
    x /= 10;
    n++;
  }
  return n;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 100;
  for (ll i = 0; i <= sqrt(n); i++) {
    if (n % i == 0) {
      ll temp = max(digitcal(i), digitcal(n / i));
      ans = min(ans, temp);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <fstream>
#include <iostream>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

ll mod(ll a, ll b) {
  ll ret = a % b;
  if (ret < 0)
    ret += b;
  return ret;
}

ll modpow(ll a, ll b, ll c) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = mod(res * a, c);
    a = mod(a * a, c);
    b >>= 1;
  }
  return res;
}

ll digitcal(ll x) {
  ll n = 0;
  while (x > 0) {
    x /= 10;
    n++;
  }
  return n;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 100;
  for (ll i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      ll temp = max(digitcal(i), digitcal(n / i));
      ans = min(ans, temp);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03775 (C++)

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

int GetDigitsCount(long long N) {
  int digitsCount = 0;
  while (N != 0) {
    digitsCount++;
    N /= 10;
  }
  return digitsCount;
}

int main() {

  long long N;
  long long B;
  int F;
  int answer = 2147483647;

  cin >> N;

  for (long long A = 1; A <= (N + 1) / 2; A++) {

    if ((N % A) == 0) {

      B = N / A;
      F = max(GetDigitsCount(A), GetDigitsCount(B));
      answer = min(answer, F);
    }
  }

  cout << answer << endl;

  return 0;
}

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

int GetDigitsCount(long long N) {
  int digitsCount = 0;
  while (N != 0) {
    digitsCount++;
    N /= 10;
  }
  return digitsCount;
}

int main() {

  long long N;
  long long B;
  int F;
  int answer = 2147483647;

  cin >> N;

  for (long long A = 1LL; A * A <= N; A++) {

    if ((N % A) == 0) {

      B = N / A;
      F = max(GetDigitsCount(A), GetDigitsCount(B));
      answer = min(answer, F);
    }
  }

  cout << answer << endl;

  return 0;
}
Problem p03775 (C++)

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

// 入力：整数N
// 出力：Nの平方根以下の最大の整数
int64_t sqrt(int64_t x) {
  int64_t s = 0;
  for (int64_t i = 0; i <= x; i++) {
    if (i * i > x) {
      s = i - 1;
      break;
    }
  }
  return s;
}

// 入力：整数N
// 出力:AB＝Nなる(A,B)であって|A-B|が最小の組(A,B)（AはB以下）のBの方
int64_t factor(int64_t N) {
  int64_t B = 0; // B=0と初期化するのを省略するとバグる
  for (int64_t i = 0; i < sqrt(N); i++) {
    if (N % (sqrt(N) - i) == 0) {
      B = N / (sqrt(N) - i);
      break;
    }
  }
  return B;
}

/*
//入力：整数N
//出力：10進表記でのNの桁数
int64_t digit(int64_t x){
    int64_t d=1;
    for(int64_t i=0; i < x;i++){
        if( pow(10,i) <= x && x < pow(10,i+1)){
            d = i+1 ;
            break ;
        }
    }
    return d;
}
*/

// 入力：整数N
// 出力：10進表記でのNの桁数
int digit(int64_t x) {
  int counter = 0;
  if (x == 0) {
    return 1;
  }
  while (x != 0) {
    x = x / 10;
    counter++;
  }
  return counter;
}

int main() {

  // 入力を受け取る
  int64_t N;
  cin >> N;

  cout << digit(factor(N)) << endl;
}


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

// 入力：整数N
// 出力：Nの平方根以下の最大の整数
int64_t sqrt(int64_t x) {
  int64_t s = 0;
  for (int64_t i = 0; i <= x; i++) {
    if (i * i > x) {
      s = i - 1;
      break;
    }
  }
  return s;
}

// 入力：整数N
// 出力:AB＝Nなる(A,B)であって|A-B|が最小の組(A,B)（AはB以下）のBの方
int64_t factor(int64_t N) {
  int64_t B = 0; // B=0と初期化するのを省略するとバグる
  int64_t M = sqrt(N);
  for (int64_t i = 0; i < M; i++) {
    if (N % (M - i) == 0) {
      B = N / (M - i);
      break;
    }
  }
  return B;
}

/*
//入力：整数N
//出力：10進表記でのNの桁数
int64_t digit(int64_t x){
    int64_t d=1;
    for(int64_t i=0; i < x;i++){
        if( pow(10,i) <= x && x < pow(10,i+1)){
            d = i+1 ;
            break ;
        }
    }
    return d;
}
*/

// 入力：整数N
// 出力：10進表記でのNの桁数
int digit(int64_t x) {
  int counter = 0;
  if (x == 0) {
    return 1;
  }
  while (x != 0) {
    x = x / 10;
    counter++;
  }
  return counter;
}

int main() {

  // 入力を受け取る
  int64_t N;
  cin >> N;

  cout << digit(factor(N)) << endl;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  ll n, a = 0, b = 0;
  cin >> n;
  for (a = (ll)sqrt(n); a <= n; a++) {
    if (n % a == 0)
      break;
  }
  a = max(a, n / a);
  cout << to_string(a).length() << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  ll n, a = 0, b = 0;
  cin >> n;
  a = (ll)sqrt(n);
  while (n % a != 0)
    --a;
  a = max(a, n / a);
  cout << to_string(a).length() << endl;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ans = 1e10;
  for (int i = 1; i * i <= n; ++i) {
    if ((double)n / i != n / i) {
      continue;
    }
    int keta1 = 0;
    long long num1 = i;
    while (num1) {
      keta1++;
      num1 /= 10;
    }
    int keta2 = 0;
    long long num2 = n / i;
    while (num2) {
      keta2++;
      num2 /= 10;
    }
    if (max(keta1, keta2) < ans) {
      ans = max(keta1, keta2);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ans = 1e10;
  for (long long i = 1; i * i <= n; ++i) {
    // long long : nと合わせないと事故る
    if ((double)n / i != n / i) {
      continue;
    }
    int keta1 = 0;
    long long num1 = i;
    while (num1) {
      keta1++;
      num1 /= 10;
    }
    int keta2 = 0;
    long long num2 = n / i;
    while (num2) {
      keta2++;
      num2 /= 10;
    }
    if (max(keta1, keta2) < ans) {
      ans = max(keta1, keta2);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9 + 7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
// template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b %
// 2 ? a : 1) : 1; }
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  ll n;
  cin >> n;

  int ans = 20;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      chmin(ans, max(sz(to_string(i)), sz(to_string(n / i))));
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9 + 7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
// template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b %
// 2 ? a : 1) : 1; }
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  ll n;
  cin >> n;

  int ans = 20;
  for (int i = 1; (ll)i * i <= n; ++i) {
    if (n % i == 0) {
      chmin(ans, max(sz(to_string(i)), sz(to_string(n / i))));
    }
  }
  cout << ans << endl;
}
Problem p03775 (C++)

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

int func(int64_t a) {
  int ad;
  if (a < 10)
    ad = 1;
  else if (a < 100)
    ad = 2;
  else if (a < 1000)
    ad = 3;
  else if (a < 10000)
    ad = 4;
  else if (a < 100000)
    ad = 5;
  else if (a < 1000000)
    ad = 6;
  else if (a < 10000000)
    ad = 7;
  else if (a < 100000000)
    ad = 8;
  else if (a < 1000000000)
    ad = 9;
  else if (a < 10000000000)
    ad = 10;
  else
    ad = 11;
  return ad;
}

int main() {
  int64_t N;
  cin >> N;

  int ans = 100;
  for (int64_t i = 1; i <= (N + 1) / 2; i++) {
    if (N % i == 0) {
      int64_t A = i;
      int64_t B = N / i;
      int digit = func(max(A, B));
      if (digit < ans)
        ans = digit;
    }
  }
  cout << ans << endl;
}

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

int func(int64_t a) {
  int ad;
  if (a < 10)
    ad = 1;
  else if (a < 100)
    ad = 2;
  else if (a < 1000)
    ad = 3;
  else if (a < 10000)
    ad = 4;
  else if (a < 100000)
    ad = 5;
  else if (a < 1000000)
    ad = 6;
  else if (a < 10000000)
    ad = 7;
  else if (a < 100000000)
    ad = 8;
  else if (a < 1000000000)
    ad = 9;
  else if (a < 10000000000)
    ad = 10;
  else
    ad = 11;
  return ad;
}

int main() {
  int64_t N;
  cin >> N;

  int ans = 100;
  for (int64_t i = 1; i <= sqrt(N) + 1; i++) {
    if (N % i == 0) {
      int64_t A = i;
      int64_t B = N / i;
      int digit = func(max(A, B));
      if (digit < ans)
        ans = digit;
    }
  }
  cout << ans << endl;
}
Problem p03775 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int num_digits(ll x) {
  int cnt = 0;
  while (x != 0) {
    x /= 10;
    cnt++;
  }
  return cnt;
}

bool is_integer(double x) { return x == floor(x); }

int main() {
  ll n;
  cin >> n;
  ll Max_div;
  for (ll i = 1LL; i * i < n; i++) {
    if (is_integer((long double)n / i)) {
      Max_div = i;
    }
  }
  cout << max(num_digits(Max_div), num_digits(n / Max_div)) << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int num_digits(ll x) {
  int cnt = 0;
  while (x != 0) {
    x /= 10;
    cnt++;
  }
  return cnt;
}

bool is_integer(double x) { return x == floor(x); }

int main() {
  ll n;
  cin >> n;
  ll Max_div;
  for (ll i = 1LL; i * i <= n; i++) {
    if (is_integer((long double)n / i)) {
      Max_div = i;
    }
  }
  cout << max(num_digits(Max_div), num_digits(n / Max_div)) << endl;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

int digits(long long n) {
  int sum = 0;
  while (n > 0) {
    n /= 10;
    sum++;
  }
  return sum;
}

int main() {
  long long n;
  cin >> n;

  int result = 0;
  result = digits(n);

  for (int i = 1; i * i <= n; i++) {
    if (n % i != 0) {
      continue;
    }

    long long j = n / i;
    int sum = max(digits(i), digits(j));
    if (result > sum) {
      result = sum;
    }
  }
  cout << result << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

int digits(long long n) {
  int sum = 0;
  while (n > 0) {
    n /= 10;
    sum++;
  }
  return sum;
}

int main() {
  long long n;
  cin >> n;

  int result = 0;
  result = digits(n);

  for (long long i = 1; i * i <= n; i++) {
    if (n % i != 0) {
      continue;
    }

    long long j = n / i;
    int sum = max(digits(i), digits(j));
    if (result > sum) {
      result = sum;
    }
  }
  cout << result << endl;
}
Problem p03775 (C++)

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

int main() {
  long long n;
  cin >> n;
  long long d = sqrt(n);
  while (n % d)
    d++;
  cout << to_string(d).size() << endl;
}


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

int main() {
  long long n;
  cin >> n;
  long long d = sqrt(n);
  while (n % d)
    d--;
  cout << to_string(n / d).size() << endl;
}
Problem p03775 (C++)

Buggy submission (status: Runtime Error):
// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF = 1e9 + 5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const ll MOD = 1000000007LL;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      res.push_back(n / i);
    }
  }
  return res;
}
int main() {
  ll n;
  cin >> n;
  vector<ll> vec = divisor(n);
  ll MIN = INF;
  for (int i = 0; i < n; i += 2) {
    string s = to_string(vec[i]);
    string t = to_string(vec[i + 1]);
    ll a = s.size();
    ll b = t.size();
    MIN = min(MIN, max(a, b));
  }
  cout << MIN << endl;
}

Fixed submission:
// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF = 1e9 + 5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const ll MOD = 1000000007LL;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      res.push_back(n / i);
    }
  }
  return res;
}
int main() {
  ll n;
  cin >> n;
  vector<ll> vec = divisor(n);
  ll MIN = INF;
  for (int i = 0; i < vec.size(); i += 2) {
    string s = to_string(vec[i]);
    string t = to_string(vec[i + 1]);
    ll a = s.size();
    ll b = t.size();
    MIN = min(MIN, max(a, b));
  }
  cout << MIN << endl;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
long long INF = 1000000000000000000;
long long mod = 1000000007;
using namespace std;

int main() {

  long long N;
  cin >> N;
  long long ans = 0;
  for (long long p = sqrt(N); p > 0; p--) {

    if (N % p == 0) {
      ans = p;
      break;
    }
  }

  ans = max(ans, N / ans);
  int x = 10;
  int cnt = 0;
  while (1) {
    cnt++;
    if (ans < x) {
      cout << cnt << endl;
      return 0;
    }
    x *= 10;
  }

  return 0;
}
/*
10000

3

1000003

7

9876543210

6
*/

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
long long INF = 1000000000000000000;
long long mod = 1000000007;
using namespace std;

int main() {

  long long N;
  cin >> N;
  long long ans = 0;
  for (long long p = sqrt(N); p > 0; p--) {

    if (N % p == 0) {
      ans = p;
      break;
    }
  }

  ans = max(ans, N / ans);
  long long x = 10;
  int cnt = 0;
  while (1) {
    cnt++;
    if (ans < x) {
      cout << cnt << endl;
      return 0;
    }
    x *= 10;
  }

  return 0;
}
/*
10000

3

1000003

7

9876543210

6
*/
Problem p03775 (C++)

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

int main() {
  int64_t n, f = 114514;
  cin >> n;
  bool even;
  int digit;
  if (n % 2 == 0)
    even = true;
  else
    even = false;
  if (to_string(n).size() == 1)
    digit = 1;
  else if (to_string(n).size() % 2 != 0)
    digit = to_string(n).size() / 2 + 1;
  else
    digit = to_string(n).size() / 2;
  if (even) {
    for (int64_t i = 1; i <= n / 2; i++) {
      if ((n % (2 * i)) != 0)
        continue;
      int64_t b = n / (2 * i);
      f = min(f, max((int64_t)to_string(2 * i).size(),
                     (int64_t)to_string(b).size()));
      if ((int)to_string(2 * i).size() > digit)
        break;
    }
  } else {
    for (int64_t i = 1; i <= (n + 1) / 2; i++) {
      if (n % (2 * i - 1) != 0)
        continue;
      int64_t b = n / (2 * i - 1);
      f = min(f, max((int64_t)to_string(2 * i - 1).size(),
                     (int64_t)to_string(b).size()));
      if ((int)to_string(2 * i - 1).size() > digit)
        break;
    }
  }
  cout << f << endl;
}


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

int main() {
  int64_t n, f = 114514;
  cin >> n;
  for (int64_t i = 1; i <= (int64_t)sqrt(n) + 1; i++) {
    if (n % i != 0)
      continue;
    int64_t b = n / i;
    f = min(f, (int64_t)max(to_string(i).size(), to_string(b).size()));
  }
  cout << f << endl;
}
Problem p03775 (C++)

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

int countOfDigits(unsigned long long n) {
  int count = 0;
  while (n > 0) {
    n /= 10;
    count++;
  }
  return count;
}

int f(unsigned long long int a, unsigned long long int b) {
  int sampleA = countOfDigits(a);
  int sampleB = countOfDigits(b);
  return max(sampleA, sampleB);
}

int main() {
  unsigned long long N;
  cin >> N;
  unsigned long long b;
  int ans = 1000;
  for (unsigned long long a = 1; a <= N; a++) {
    if (N % a != 0)
      continue;
    b = N / a;
    int tmp = f(a, b);
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


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

int countOfDigits(unsigned long long n) {
  int count = 0;
  while (n > 0) {
    n /= 10;
    count++;
  }
  return count;
}

int f(unsigned long long int a, unsigned long long int b) {
  int sampleA = countOfDigits(a);
  int sampleB = countOfDigits(b);
  return max(sampleA, sampleB);
}

int main() {
  unsigned long long N;
  cin >> N;
  unsigned long long b;
  int ans = 1000;
  for (unsigned long long a = 1; a <= sqrt(N); a++) {
    if (N % a != 0)
      continue;
    b = N / a;
    int tmp = f(a, b);
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}
Problem p03775 (C++)

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

bool SecondCompare(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}

bool SecondCompareDes(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second > b.second;
}

long long n;
long long ans = LLONG_MAX, mem;
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    if (n % i == 0) {
      mem = max(i, n / i);
      ans = min(ans, mem);
    }
  }

  int cou = 0;
  while (ans > 0) {
    ans /= 10;
    ++cou;
  }
  cout << cou << endl;
}


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

bool SecondCompare(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}

bool SecondCompareDes(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second > b.second;
}

long long n;
long long ans = LLONG_MAX, mem;
int main() {
  cin >> n;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      mem = max(i, n / i);
      ans = min(ans, mem);
    }
  }

  int cou = 0;
  while (ans > 0) {
    ans /= 10;
    ++cou;
  }
  cout << cou << endl;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool is_prime(ll n) {
  if (n == 1)
    return false;                   // 1 は素数ではない。
  for (ll i = 2; i * i <= n; ++i) { // 2 <= i <= sqrt(n) に約数があれば、
    if (n % i == 0)
      return false; // n は素数ではない
  }
  return true;
}
int main() {
  ll n, ans = 0;
  cin >> n;
  if (is_prime(n)) {
    while (1) {
      if (n == 0)
        break;
      ans++;
      n /= 10;
    }
    cout << ans << endl;
  } else {
    ll k = sqrt(n), i;
    for (i = k;; i++) {
      if (n % i == 0)
        break;
    }
    ll p = n / i, ans1 = 0;
    while (1) {
      if (p == 0)
        break;
      ans1++;
      p /= 10;
    }
    while (1) {
      if (i == 0)
        break;
      ans++;
      i /= 10;
    }
    cout << max(ans, ans1) << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool is_prime(ll n) {
  if (n == 1)
    return false;                   // 1 は素数ではない。
  for (ll i = 2; i * i <= n; ++i) { // 2 <= i <= sqrt(n) に約数があれば、
    if (n % i == 0)
      return false; // n は素数ではない
  }
  return true;
}
int main() {
  ll n, ans = 0;
  cin >> n;
  if (is_prime(n)) {
    while (1) {
      if (n == 0)
        break;
      ans++;
      n /= 10;
    }
    cout << ans << endl;
  } else {
    ll k = sqrt(n), i;
    for (i = k;; i--) {
      if (n % i == 0)
        break;
    }
    ll p = n / i, ans1 = 0;
    while (1) {
      if (p == 0)
        break;
      ans1++;
      p /= 10;
    }
    while (1) {
      if (i == 0)
        break;
      ans++;
      i /= 10;
    }
    cout << max(ans, ans1) << endl;
  }
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;

int cnt_digits(ll n) {
  int digits = 0;
  while (n > 0) {
    n /= 10;
    digits++;
  }
  return digits;
}

int main() {
  ll n, a, b;
  cin >> n;
  ll ans = cnt_digits(n);
  for (int a = 1; a * a <= n; a++) {
    if (n % a != 0)
      continue;
    b = n / a;
    int cur = max(cnt_digits(a), cnt_digits(b));
    if (cur < ans) {
      ans = cur;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;

int cnt_digits(ll n) {
  int digits = 0;
  while (n > 0) {
    n /= 10;
    digits++;
  }
  return digits;
}

int main() {
  ll n, a, b;
  cin >> n;
  ll ans = cnt_digits(n);
  for (ll a = 1; a * a <= n; a++) {
    if (n % a != 0)
      continue;
    b = n / a;
    int cur = max(cnt_digits(a), cnt_digits(b));
    if (cur < ans) {
      ans = cur;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main() {
  long long n;
  cin >> n;

  int l;
  long stocks = 1000;

  for (int i = 1; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    string s = to_string(n / i);
    if (s.size() < stocks)
      stocks = s.size();
  }

  cout << stocks << endl;
}

Fixed submission:
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main() {
  long long n;
  cin >> n;

  int l;
  long stocks = 1000;

  for (long long i = 1; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    string s = to_string(n / i);
    if (s.size() < stocks)
      stocks = s.size();
  }

  cout << stocks << endl;
}
Problem p03775 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>

using namespace std;

unsigned long long int N, l, m = 9999999999999;

unsigned long long int ten(unsigned long long int ou);

int main() {

  cin >> N;

  for (unsigned long long int i; i < sqrt(N); i++) {
    if ((N % i) == 0) {
      l = ten(N / i);
      if (l < m)
        m = l;
    }
  }
  cout << m;
}

unsigned long long int ten(unsigned long long int ou) {
  unsigned long long int i;
  for (i = 1;; i++) {
    ou /= 10;
    if (ou == 0)
      break;
  }
  return i;
}

Fixed submission:
#include <cmath>
#include <iostream>

using namespace std;

unsigned long long int N, l, m = 9999999999999;

unsigned long long int ten(unsigned long long int ou);

int main() {

  cin >> N;

  for (unsigned long long int i = 1; i <= sqrt(N); i++) {
    if ((N % i) == 0) {
      l = ten(N / i);
      if (l < m)
        m = l;
    }
  }
  cout << m;
}

unsigned long long int ten(unsigned long long int ou) {
  unsigned long long int i;
  for (i = 1;; i++) {
    ou /= 10;
    if (ou == 0)
      break;
  }
  return i;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
using namespace std;

int keta(long long int a) {
  int cou = 0;
  while (a != 0) {
    a /= 10;
    cou++;
  }
  return cou;
}

int main(void) {
  const long long int mod = 1000000007;
  long long int n, m = 0, a[200005], plsum = 0, misum = 0, pl = 0, mi = 0;
  cin >> n;
  for (int i = 0; i * i <= n; i++) {
    m = i;
  }
  for (int i = m; i >= 0; i--) {
    if (n % i == 0) {
      cout << keta(n / i);
      return 0;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
using namespace std;

int keta(long long int a) {
  int cou = 0;
  while (a != 0) {
    a /= 10;
    cou++;
  }
  return cou;
}

int main(void) {
  const long long int mod = 1000000007;
  long long int n, m = 0, a[200005], plsum = 0, misum = 0, pl = 0, mi = 0;
  cin >> n;
  for (long long int i = 0; i * i <= n; i++) {
    m = i;
  }
  for (int i = m; i >= 0; i--) {
    if (n % i == 0) {
      cout << keta(n / i);
      return 0;
    }
  }
}
Problem p03775 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
using namespace std;
int main(void) {
  long long N;
  cin >> N;
  long long Amax = sqrt(N);
  for (long long A = Amax; A > 0; A--) {
    if (N % A == 0) {
      long long B = N / A;
      // 必ず、B>=Aなので、Bの桁数を数える
      int ans = 1;
      int div = 10;
      for (;;) {
        if (B / div == 0) {
          cout << ans << endl;
          return 0;
        }
        div *= 10;
        ans++;
      }
    }
  }
  return 0; // ここには来ない
}


Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
int main(void) {
  long long N;
  cin >> N;
  long long Amax = sqrt(N);
  for (long long A = Amax; A > 0; A--) {
    if (N % A == 0) {
      long long B = N / A;
      // 必ず、B>=Aなので、Bの桁数を数える
      int ans = 1;
      long long div = 10;
      for (;;) {
        if (B / div == 0) {
          cout << ans << endl;
          return 0;
        }
        div *= 10;
        ans++;
      }
    }
  }
  return 0; // ここには来ない
}