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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int, int> P;

int main() {
  ll n;
  cin >> n;
  double ans = -1 * INF;
  for (double i = 1; i <= n / 2; ++i) {
    double j = n / i;
    if (j != int(n / i))
      continue;
    ans = min(ans, i + j - 2);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int, int> P;

int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (ll i = 1; i <= pow(n, 0.5); ++i) {
    ll j = n / i;
    if (n % i != 0)
      continue;
    ans = min(ans, i + j - 2);
  }
  cout << ans << endl;
  return 0;
}
Problem p02881 (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;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll a = 1;
  ll b = 1;

  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      a = i;
    }
  }
  b = n / a;
  ll ans;
  ans = a + b - 2;
  cout << ans << endl;
  return 0;
}


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

int main() {
  ll n;
  cin >> n;
  ll a = 1;
  ll b = 1;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      a = i;
    }
  }
  b = n / a;
  ll ans;
  ans = a + b - 2;
  cout << ans << endl;
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (long i = 1; i <= n; i++)
using namespace std;
int main(void) {
  long n;
  double tmp;
  long ans = 1000000000005;
  cin >> n;
  rep(i, n / 2 + 1) {
    tmp = (double)n / i;
    if (floor(tmp) != (tmp))
      continue;
    if (ans > i + tmp - 2)
      ans = i + tmp - 2;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long i = 1; i <= n; i++)
using namespace std;
int main(void) {
  long n;
  double tmp;
  long ans = 1000000000005;
  cin >> n;
  rep(i, sqrt(n) + 1) {
    tmp = (double)n / i;
    if (floor(tmp) != (tmp))
      continue;
    if (ans > i + tmp - 2)
      ans = i + tmp - 2;
  }
  cout << ans;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N;
  cin >> N;
  for (ll i = sqrt(N); i >= 1; i++) {
    if (N % i == 0) {
      cout << i + (N / i) - 2 << endl;
      break;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N;
  cin >> N;
  for (ll i = sqrt(N); i >= 1; i--) {
    if (N % i == 0) {
      cout << i + (N / i) - 2 << endl;
      break;
    }
  }
  return 0;
}
Problem p02881 (C++)

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

int main() {
  ll n;
  cin >> n;
  ll n1, n2 = 0;
  ll ans = 1e+13;

  for (ll i = 1; i < floor(n / 2) + 1; i++) {
    // cout << "i = " << i << " n/i = " << n/i << " ans = "<<ans<<endl;
    if ((n / i) * i == n) {
      n1 = i;
      n2 = (n / i);
      ll a = n1 + n2 - 2;
      // cout << a << endl;
      if (a < ans)
        ans = a;
    }
  }
  cout << ans;
}

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

int main() {
  ll n;
  cin >> n;
  ll n1, n2 = 0;
  ll ans = 1e+13;

  for (ll i = 1; i < sqrt(n) + 1; i++) {
    if (ans > i + (n / i) - 2 && i * (n / i) == n) {
      ans = i + (n / i) - 2;
    }
  }
  cout << ans;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  long long int n, i;
  cin >> n;
  i = sqrt(n);
  while (1) {
    if (n % i == 0) {
      cout << n / i + i - 2;
      break;
    }
    i++;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  long long int n, i;
  cin >> n;
  i = sqrt(n);
  while (1) {
    if (n % i == 0) {
      cout << n / i + i - 2;
      break;
    }
    i--;
  }
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):

#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() { cerr << endl; }

template <typename H, typename... T> void d_err(H h, T... t) {
  cerr << h << " ";
  d_err(t...);
}

template <typename T> void print(T x) { cout << x << endl; }

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9 + 7;

void divisor(ll N, vll &ret) {}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll N;
  cin >> N;

  ll ans = INF;
  for (int i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      ans = min(ans, i + N / i - 2);
    }
  }

  print(ans);
}


Fixed submission:

#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() { cerr << endl; }

template <typename H, typename... T> void d_err(H h, T... t) {
  cerr << h << " ";
  d_err(t...);
}

template <typename T> void print(T x) { cout << x << endl; }

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9 + 7;

void divisor(ll N, vll &ret) {}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll N;
  cin >> N;

  ll ans = INF;
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      ans = min(ans, i + N / i - 2);
    }
  }

  print(ans);
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define m7 1000000007
#define m9 1000000009
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second

using namespace std;
int main() {

  ll a, n;
  cin >> n;
  a = n - 1;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      a = min(a, n / i + i - 2);
    }
  }
  cout << a;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define m7 1000000007
#define m9 1000000009
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second

using namespace std;
int main() {

  ll a, n;
  cin >> n;
  a = n - 1;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      a = min(a, n / i + i - 2);
    }
  }
  cout << a;
  return 0;
}
Problem p02881 (C++)

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

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

  int64_t start = int64_t(sqrt(n));
  if (start * start == n) {
    cout << 2 * (start - 1) << endl;
    return 1;
  }

  while (n % start != 0)
    start--;

  int64_t ans = (start - 1) + (n / start - 1);

  cout << ans << endl;

  return 0;
}

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

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

  int64_t start = int64_t(sqrt(n));
  // if(start*start == n) {
  //   cout<<2*(start-1)<<endl;
  //   return 1;
  // }

  while (n % start != 0)
    start--;

  int64_t ans = (start - 1) + (n / start - 1);

  cout << ans << endl;

  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(n) n.begin(), n.end()
#define yn(x) cout << (x ? "Yes" : "No") << endl;

int main() {
  ll n;
  cin >> n;
  ll ans = n;
  rep(i, n + 1) {
    rep(j, n + 1) {
      if (n == i * j)
        ans = min(ans, i + j - 2);
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(n) n.begin(), n.end()
#define yn(x) cout << (x ? "Yes" : "No") << endl;

int main() {
  ll n;
  cin >> n;
  ll ans;
  for (ll i = sqrt(n); i > 0; i--) {
    if (n % i == 0) {
      ans = i + n / i - 2;
      break;
    }
  }
  cout << ans << endl;
}
Problem p02881 (C++)

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

long long int a, b;

int main() {
  cin >> a;
  b = 0;
  for (int i = 1; i * i <= a; i++) {

    if (a % i == 0) {
      b = i;
    }
  }

  cout << a / b + b - 2 << endl;
}


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

long long int a, b;

int main() {
  cin >> a;
  b = 0;
  for (long long int i = 1; i * i <= a; i++) {

    if (a % i == 0) {
      b = i;
    }
  }

  cout << a / b + b - 2 << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;

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

  ll ans = N - 1;

  for (ll i = 1; i * i <= N; i++) {
    for (ll j = i; i * j <= N; j++) {
      if (i * j == N) {
        if (ans > i + j - 2)
          ans = i + j - 2;
      }
    }
  }

  cout << ans << endl;
}

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

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

  ll ans = N - 1;

  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ll j = N / i;
      ans = min(ans, j + i - 2);
    }
  }

  cout << ans << endl;
}
Problem p02881 (C++)

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

using namespace std;
int main() {
  long long buf, n, ans;
  cin >> n;
  buf = 1;
  std::vector<long long> vec;
  while (buf <= n / 2) {
    if (n % buf == 0) {
      vec.push_back(n / buf + buf - 2);
      // cout << n/buf;
      // cout << " ";
      // cout << buf;
      // cout << "  ";
    }
    buf++;
  }
  std::sort(vec.begin(), vec.end());
  cout << *vec.begin();
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
int main() {
  long long buf, n, ans;
  cin >> n;
  buf = 1;
  std::vector<long long> vec;
  while (buf <= sqrt(n)) {
    if (n % buf == 0) {
      vec.push_back(n / buf + buf - 2);
      // cout << n/buf;
      // cout << " ";
      // cout << buf;
      // cout << "  ";
    }
    buf++;
  }
  std::sort(vec.begin(), vec.end());
  cout << *vec.begin();
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define max 1e12

using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int count = 0;
  long long int min = max;
  long long int j = 0;
  for (long long int i = 1; i <= n / 2; i++) {
    if (n % i == 0) {
      j = n / i;
      count = i + j - 2;
      if (min > count)
        min = count;
    }
  }
  cout << min << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define max 1e12

using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long count = 0;
  long long min = max;
  long long j = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      j = n / i;
      count = i + j - 2;
      if (min > count)
        min = count;
    }
  }
  cout << min << endl;
  return 0;
}
Problem p02881 (C++)

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

int main(void) {
  ul n;
  cin >> n;
  ul ans = n - 1;
  for (ul i = 0; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    ans = min(ans, i + n / i - 2);
  }
  cout << ans << endl;
  return 0;
}

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

int main(void) {
  ul n;
  cin >> n;
  ul ans = n - 1;
  for (ul i = 1; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    ans = min(ans, i + n / i - 2);
  }
  cout << ans << endl;
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  ll n;
  cin >> n;
  string flag = "No";
  int Max = pow(10, 6);
  ll res = pow(10, 13);
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ll ans = n / i + i - 2;
      res = min(res, ans);
    }
  }
  cout << res << endl;
  // cout<<flag<<endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  ll n;
  cin >> n;
  string flag = "No";
  int Max = pow(10, 6);
  ll res = pow(10, 13);
  for (int i = 1; i <= Max; i++) {
    if (n % i == 0) {
      ll ans = n / i + i - 2;
      res = min(res, ans);
    }
  }
  cout << res << endl;
  // cout<<flag<<endl;
}
Problem p02881 (C++)

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

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

  int s = sqrt(n);
  while (s--) {
    if (n % s == 0) {
      cout << s + (n / s) - 2 << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using pint = pair<int, int>;

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

  int s = sqrt(n) + 1;
  while (s--) {
    if (n % s == 0) {
      cout << s + (n / s) - 2 << endl;
      return 0;
    }
  }
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  stack<ll> S;
  for (int i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      S.push(i);
    }
  }
  ll b = N / S.top();
  cout << S.top() + b - 2 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  stack<ll> S;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      S.push(i);
    }
  }
  ll b = N / S.top();
  cout << S.top() + b - 2 << endl;
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main() {
  cout << fixed << setprecision(10);
  ll N;
  cin >> N;
  ll M = pow(N, 0.5);
  ll ans = 100000000000000;
  for (ll i = M; i < N; i++) {
    if (N % i == 0) {
      cout << i + (N / i) - 2 << endl;
      return 0;
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main() {
  cout << fixed << setprecision(10);
  ll N;
  cin >> N;
  ll M = pow(N, 0.5);
  ll ans = 100000000000000;
  for (ll i = M; i > 0; i--) {
    if (N % i == 0) {
      cout << i + (N / i) - 2 << endl;
      return 0;
    }
  }
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T> void cout_vec(const vector<T> &vec1) {
  rep(i, len(vec1)) { cout << vec1[i] << ' '; }
  cout << '\n';
}

typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;
const ll min_max = 1e12;

ll gcd(ll a, ll b) {
  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

// 単純な素数か素数じゃないかの問題ではない。
int main() {

  ll A;
  cin >> A;

  ll first = 1;
  ll second = 1;
  ll min = min_max + 1;

  if (A <= 1e6) {
    for (int i = 1; i <= A; i++) {
      if (A % i == 0) {
        if (i + A / i <= min) {
          first = i;
          second = A / i;
          min = first + second;
        }
      }
    }
  } else {
    for (int i = 1; i < A / 1000; i++) {
      if (A % i == 0) {
        if (i + A / i <= min) {
          first = i;
          second = A / i;
          min = first + second;
        }
      }
    }
  }

  ll ans = 0;

  if (first == 1 || second == 1) {
    cout << A - 1 << endl;
  } else {
    cout << min - 2 << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T> void cout_vec(const vector<T> &vec1) {
  rep(i, len(vec1)) { cout << vec1[i] << ' '; }
  cout << '\n';
}

typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;
const ll min_max = 1e12;

ll gcd(ll a, ll b) {
  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

// 単純な素数か素数じゃないかの問題ではない。
int main() {

  ll A;
  cin >> A;

  ll first = 1;
  ll second = 1;
  ll min = min_max + 1;

  if (A <= 1e6) {
    for (int i = 1; i <= A; i++) {
      if (A % i == 0) {
        if (i + A / i <= min) {
          first = i;
          second = A / i;
          min = first + second;
        }
      }
    }
  } else {
    for (int i = 1; i < A / 100000; i++) {
      if (A % i == 0) {
        if (i + A / i <= min) {
          first = i;
          second = A / i;
          min = first + second;
        }
      }
    }
  }

  ll ans = 0;

  if (first == 1 || second == 1) {
    cout << A - 1 << endl;
  } else {
    cout << min - 2 << endl;
  }

  return 0;
}
Problem p02881 (C++)

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

int main() {
  ll n;
  cin >> n;
  map<int, int> memo;
  for (int i = 0; i <= sqrt(n); i++) {
    if (n % i == 0)
      memo[i]++;
  }
  ll ans = 1e13;
  for (auto itr = memo.begin(); itr != memo.end(); itr++) {
    ans = min(ans, (itr->first) + n / (itr->first) - 2);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  ll n;
  cin >> n;
  map<int, int> memo;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0)
      memo[i]++;
  }
  ll ans = 1e13;
  for (auto itr = memo.begin(); itr != memo.end(); itr++) {
    ans = min(ans, (itr->first) + n / (itr->first) - 2);
  }
  cout << ans << endl;
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long n;
  long i, mod, div, tmp;
  long ans;

  cin >> n;
  ans = n - 1;

  for (i = 1; i < n; i++) {
    mod = n % i;
    if (mod == 0) {
      div = n / i;
      tmp = (div - 1) + (i - 1);
      ans = min(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long n;
  long i, mod, div, tmp;
  long ans;

  cin >> n;
  ans = n - 1;

  for (i = 1; i * i <= n; i++) {
    mod = n % i;
    if (mod == 0) {
      div = n / i;
      tmp = (div - 1) + (i - 1);
      ans = min(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02881 (C++)

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

#define int64 long long
#define pii pair<int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii {
  int64 fr, sc, th;
  bool operator<(const piii &b) {
    if (fr != b.fr)
      return fr < b.fr;
    if (sc != b.sc)
      return sc < b.sc;
    return th < b.th;
  }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int main() {
  cout << setprecision(2) << fixed;
  ios::sync_with_stdio(false), cin.tie(0);
  // freopen("input.txt", "r", stdin);
  int64 n;
  cin >> n;
  int64 res = n + 3;
  for (int i = 1; i * i <= n; i++)
    if (n % i == 0) {
      res = min(res, i + n / i);
    }
  cout << res - 2;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define int64 long long
#define pii pair<int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii {
  int64 fr, sc, th;
  bool operator<(const piii &b) {
    if (fr != b.fr)
      return fr < b.fr;
    if (sc != b.sc)
      return sc < b.sc;
    return th < b.th;
  }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int main() {
  cout << setprecision(2) << fixed;
  ios::sync_with_stdio(false), cin.tie(0);
  // freopen("input.txt", "r", stdin);
  int64 n;
  cin >> n;
  int64 res = n + 3;
  for (int64 i = 1; i * i <= n; i++)
    if (n % i == 0) {
      res = min(res, i + n / i);
    }
  cout << res - 2;
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long prime(long long a) {
  long long y, i;
  y = sqrt(a);
  for (i = 2; i <= y; i++) {
    if (a % i == 0) {
      return -1;
    }
  }
  if (i > y)
    return 1;
}
int main() {
  long long a, c, d;
  cin >> a;
  c = prime(a);
  if (c == 1) {
    cout << a - 1;
  } else {
    d = sqrt(a);
    while (a % d != 0) {
      d++;
    }
    cout << (d - 1) + (a / d - 1);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long prime(long long a) {
  long long y, i;
  y = sqrt(a);
  for (i = 2; i <= y; i++) {
    if (a % i == 0) {
      return -1;
    }
  }
  if (i > y)
    return 1;
}
int main() {
  long long a, c, d;
  cin >> a;
  c = prime(a);
  if (c == 1) {
    cout << a - 1;
  } else {
    d = sqrt(a);
    while (a % d != 0) {
      d--;
    }
    cout << (d - 1) + (a / d - 1);
  }
  return 0;
}
Problem p02881 (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;
typedef long long ll;

int main() {
  ll n, minv = 1000000000001;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    if (n % i == 0) {
      minv = min(i + (n / i) - 2, minv);
    }
  }
  cout << minv << endl;
  return 0;
}

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

int main() {
  ll n, minv = 1000000000001;
  cin >> n;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      minv = min(i + (n / i) - 2, minv);
    }
  }
  cout << minv << endl;
  return 0;
}
Problem p02881 (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;
typedef long long ll;

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

  ll j = 1;
  for (ll i = sqrt(n); i > 1; i++) {
    if (n % i == 0) {
      j = i;
      break;
    }
  }
  ll i = n / j;

  cout << i - 1 + j - 1 << endl;
}

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

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

  ll j = 1;
  for (ll i = sqrt(n); i > 1; i--) {
    if (n % i == 0) {
      j = i;
      break;
    }
  }
  ll i = n / j;

  cout << i - 1 + j - 1 << endl;
}
Problem p02881 (C++)

Buggy submission (status: Runtime Error):
#include <bits //stdc++.h>
#define rep(i, k) for (int i = 0; i < k; i++)
#define int unsigned long long
using namespace std;
signed main(void) {
  int n, m, a, b, c, ans;
  cin >> n;

  for (int i = 1; i < n; i++) {
    if (i * i > n) {
      ans = i;
      break;
    }
  }

  for (int i = ans; i > 0; i--) {
    if (n % i == 0) {
      b = i;
      break;
    }
  }

  cout << n / b + b - 2 << endl;
}


Fixed submission:
#include <bits //stdc++.h>
#define rep(i, k) for (int i = 0; i < k; i++)
#define int unsigned long long
using namespace std;
signed main(void) {
  int n, m, a, b, c, ans;
  cin >> n;

  for (int i = 1; i < n; i++) {
    if (i * i > n) {
      ans = i;
      break;
    }
  }
  b = 1;
  for (int i = ans; i > 0; i--) {
    if (n % i == 0) {
      b = i;
      break;
    }
  }

  cout << n / b + b - 2 << endl;
}
Problem p02881 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 0; i < sqrt(n); i++) {
    if (n % i == 0) {
      ans = min(i + n / i - 2, ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    ll j = n / i;
    ans = min(i + j - 2, ans);
  }
  cout << ans << endl;
  return 0;
}
Problem p02881 (C++)

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

int main() {
  long long n;
  cin >> n;
  long long min = 10000000000000;
  for (long long i = 1; i <= n / 2; i++) {
    long long t;
    if ((n % i) == 0) {
      t = (i - 1) + ((n / i) - 1);
      if (min > t) {
        min = t;
      }
    }
  }
  cout << min << endl;
}

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

int main() {
  long long n;
  cin >> n;
  long long min = n - 1;
  long long t;
  for (long long i = 1; i <= sqrt(n); i++) {
    if ((n % i) == 0) {
      t = (i - 1) + ((n / i) - 1);
      if (min > t) {
        min = t;
      }
    }
  }
  cout << min << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  unsigned long long int min;
  long long int ans1, ans2;
  for (long long int i = 1; i <= n; i++) {
    if (n % i == 0) {
      long long int j = n / i;
      unsigned long long int min1 = sqrt(pow(i - 1, 2) + pow(j - 1, 2));
      if (min1 < min or i == 1) {
        min = min1;
        ans1 = i;
        ans2 = j;
      }
    }
  }
  cout << (ans1 - 1) + (ans2 - 1);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  unsigned long long int min;
  long long int ans1, ans2;
  for (long long int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      long long int j = n / i;
      unsigned long long int min1 = sqrt(pow(i - 1, 2) + pow(j - 1, 2));
      if (min1 < min or i == 1) {
        min = min1;
        ans1 = i;
        ans2 = j;
      }
    }
  }
  cout << (ans1 - 1) + (ans2 - 1);
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define mod 1e9 + 7
#define endl '\n'

void solve() {
  ll n;
  cin >> n;
  ll ans = 1e12;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ans = min(ans, i + n / i - 2);
    }
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--)
    solve();
  return 0;
}


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define mod 1e9 + 7
#define endl '\n'

void solve() {
  ll n;
  cin >> n;
  ll ans = 1e12;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ans = min(ans, i + n / i - 2);
    }
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--)
    solve();
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const double pi = 3.141592654;
#define pb push_back
#define forab(i, a, b) for (int i = (a); i <= (b); i++)
#define CIN                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
#define pcase(z, x) printf("Case %ld: %lld\n", z, x)
#define nw "\n"
#define mod 1000000007

int main(void) {
  CIN;
  ll tc, l, k = 0, sum = 0, x = 0, y, z = 0, m = 1, n = 0, ans = 0, cnt = 0;
  cin >> n;
  ll mx = 1e16;
  for (ll i = 1; i <= n; i++) {
    if (n % i == 0) {
      z = (i * i + n - 2 * i) / i;
      mx = min(mx, z);
    }
  }
  cout << mx;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const double pi = 3.141592654;
#define pb push_back
#define forab(i, a, b) for (int i = (a); i <= (b); i++)
#define CIN                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
#define pcase(z, x) printf("Case %ld: %lld\n", z, x)
#define nw "\n"
#define mod 1000000007

int main(void) {
  CIN;
  ll tc, l, k = 0, sum = 0, x = 0, y, z = 0, m = 1, n = 0, ans = 0, cnt = 0;
  cin >> n;
  ll mx = 1e16;
  for (ll i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      z = (i * i + n - 2 * i) / i;
      mx = min(mx, z);
    }
  }
  cout << mx;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <istream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long N;
  vector<long long> NN;
  cin >> N;

  for (long long i = 1; i < N; i++) {
    if (N % i == 0) {
      NN.push_back(i + (N / i) - 2);
    }
  }
  sort(NN.begin(), NN.end());
  cout << NN[0] << endl;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <istream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long N;
  vector<long long> NN;
  cin >> N;

  for (long long i = 1; i <= sqrt(N); i++) {
    if (N % i == 0) {
      NN.push_back(i + (N / i) - 2);
    }
  }
  sort(NN.begin(), NN.end());
  cout << NN[0] << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_MAT_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

static const int MOD = 1e9 + 7;

int main() {

  long long N;
  cin >> N;
  long long ans = N - 1;

  for (int i = 2; i * i <= N; i++) {
    if (N % i == 0)
      ans = min(ans, N / i + i - 2);
  }

  cout << ans;
}

Fixed submission:
#define _USE_MAT_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

static const int MOD = 1e9 + 7;

int main() {

  long long N;
  cin >> N;
  long long ans = N - 1;

  for (long long i = 2; i * i <= N; i++) {
    if (N % i == 0)
      ans = min(ans, N / i + i - 2);
  }

  cout << ans;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;           // 10^19 < 9223372036854775807
typedef unsigned long long ull; // 10^20 < 18446744073709551615

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())

#define MOD 1000000007

int main(void) {
  ll N;
  cin >> N;

  ll ans = 1000000000010;
  for (ll i = 1; i <= N / 2; i++) {
    if (N % i == 0) {
      ans = min((N / i - 1) + i - 1, ans);
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;           // 10^19 < 9223372036854775807
typedef unsigned long long ull; // 10^20 < 18446744073709551615

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())

#define MOD 1000000007

int main(void) {
  ll N;
  cin >> N;

  ll ans = 1000000000010;
  for (ll i = 1; i <= sqrt(N); i++) {
    if (N % i == 0) {
      ans = min((N / i - 1) + i - 1, ans);
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (long long i = init; i < (n); i++)
#define repd(i, n, init) for (long long i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main() {
  ll N;
  cin >> N;
  ll ans = INF;
  repi(i, N, 1) {
    if (N % i != 0) {
      continue;
    }
    ll j = N / i;
    ans = min(ans, i + j - 2);
  }
  cout << ans << endl;
  return 0;
}

/*memo*/
// 数学的考察をしましょう
// 表を使うときは対称性に気をつける。
// 2次元にとらわれすぎない
// 整数の性質を使う
// sqrt(N)よりかはi*i < Nのほうがよき

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (long long i = init; i * i <= (n); i++)
#define repd(i, n, init) for (long long i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main() {
  ll N;
  cin >> N;
  ll ans = INF;
  repi(i, N, 1) {
    if (N % i != 0) {
      continue;
    }
    ll j = N / i;
    ans = min(ans, i + j - 2);
  }
  cout << ans << endl;
  return 0;
}

/*memo*/
// 数学的考察をしましょう
// 表を使うときは対称性に気をつける。
// 2次元にとらわれすぎない
// 整数の性質を使う
// sqrt(N)よりかはi*i < Nのほうがよき
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, t, n) for (ll i = (t); i <= (n); ++i)
#define per(i, n, t) for (int i = (n); i >= (t); --i)
#define mmm(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define Decimal fixed << setprecision(20)
#define debug(x) cerr << #x << ":" << x << endl
#define FAST_IO                                                                \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0)
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 2e3 + 5;
typedef double db;

const int N = 10;
bool ok(int x) { return x >= 1 && x <= 9; }
int main() {
  FAST_IO;
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (int i = 1; i * i <= n; i++)
    if (n % i == 0) {
      ans = min(i + n / i, ans);
    }
  cout << ans - 2 << endl;
}
/*
2
A 0 0 2
B 1 0 2


*/


Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, t, n) for (ll i = (t); i <= (n); ++i)
#define per(i, n, t) for (int i = (n); i >= (t); --i)
#define mmm(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define Decimal fixed << setprecision(20)
#define debug(x) cerr << #x << ":" << x << endl
#define FAST_IO                                                                \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0)
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 2e3 + 5;
typedef double db;

const int N = 10;
bool ok(int x) { return x >= 1 && x <= 9; }
int main() {
  FAST_IO;
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (ll i = 1; i * i <= n; i++)
    if (n % i == 0) {
      ans = min(i + n / i, ans);
    }
  cout << ans - 2 << endl;
}
/*
2
A 0 0 2
B 1 0 2


*/
Problem p02881 (C++)

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      ans = i;
  }
  cout << n / ans + ans - 2 << endl;
  return 0;
}

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

int main() {
  ll n;
  cin >> n;
  ll ans = 1;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      ans = i;
  }
  cout << n / ans + ans - 2 << endl;
  return 0;
}
Problem p02881 (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;

int main() {
  long n, ans = LONG_MAX;
  cin >> n;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0)
      ans = min(ans, n / i + i - 2);
  }
  cout << ans << endl;
}

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

int main() {
  long n, ans = LONG_MAX;
  cin >> n;
  for (long i = 1; i * i <= n; i++) {
    if (n % i == 0)
      ans = min(ans, n / i + i - 2);
  }
  cout << ans << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES // for C++
#include "bits/stdc++.h"
#define NUM ((long long)1000000007)
#define int unsigned long long

using namespace std;

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

  auto v = vector<int>();

  for (size_t i = 1; i < n / 2 + 1; i++) {
    if (n % i == 0) {
      v.push_back(i + (n / i) - 2);
    }
  }

  cout << *min_element(v.begin(), v.end()) << endl;
}

Fixed submission:
#define _USE_MATH_DEFINES // for C++
#include "bits/stdc++.h"
#define NUM ((long long)1000000007)
#define int unsigned long long

using namespace std;

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

  auto v = vector<int>();

  for (size_t i = 1; i < sqrt(n) + 1; i++) {
    if (n % i == 0) {
      v.push_back(i + (n / i) - 2);
    }
  }

  cout << *min_element(v.begin(), v.end()) << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main() {
  ll N;
  cin >> N;
  ll p = N - 1;
  for (int i = 2; i < N; i++) {
    if (N % i == 0) {
      if ((N / i - 1) + i - 1 < p) {
        p = (N / i - 1) + i - 1;
      } else {
        break;
      }
    } else {
      continue;
    }
  }
  cout << p;
}

Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main() {
  ll N;
  cin >> N;
  ll p = N - 1;
  for (int i = 2; pow(i, 2) <= N; i++) {
    if (N % i == 0) {
      if ((N / i - 1) + i - 1 < p) {
        p = (N / i - 1) + i - 1;
      } else {
        break;
      }
    } else {
      continue;
    }
  }
  cout << p;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  long long n;
  cin >> n;
  long long min = n + 1;
  long long tmp;
  for (long long i = 1; i * 2 <= n; i++) {
    long long j;
    if (n % i == 0) {
      j = n / i;
      tmp = j + i - 2;
    }
    if (min > tmp)
      min = tmp;
  }
  cout << min << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  long long n;
  cin >> n;
  long long min = n + 1;
  long long tmp;
  for (long long i = 1; i * i <= n; i++) {
    long long j;
    if (n % i == 0) {
      j = n / i;
      tmp = j + i - 2;
    }
    if (min > tmp)
      min = tmp;
  }
  cout << min << endl;
  return 0;
}
Problem p02881 (C++)

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

int main() {

  long int N;
  cin >> N;

  long int c = N - 1;
  for (long int i = N / 2; i > 0; i--) {
    long int q;
    q = N / i;
    if (i * q == N && i + q - 2 <= c) {
      c = i + q - 2;
    }
  }
  cout << c << endl;
}


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

int main() {

  long int N;
  cin >> N;

  long int c = N - 1;
  for (long int i = (int)sqrt(N); i > 0; i--) {
    long int q;
    q = N / i;
    if (i * q == N && i + q - 2 <= c) {
      c = i + q - 2;
    }
  }
  cout << c << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n)                                                              \
  ;                                                                            \
  for (long long i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  ll r = sqrt(n);
  for (ll i = r; i <= n; i++) {
    if (n % i == 0) {
      cout << i + n / i - 2 << endl;
      break;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n)                                                              \
  ;                                                                            \
  for (long long i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  ll r = sqrt(n);
  for (ll i = r; i > 0; i--) {
    if (n % i == 0) {
      cout << i + n / i - 2 << endl;
      break;
    }
  }
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, n)                                                              \
  for (int i = 0; i < n; i++)                                                  \
    ;
using namespace std;
typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  ll result = N - 1;
  for (ll i = 1; i <= N; i++) {
    for (ll j = i; j <= N; j++) {
      if (N == i * j) {
        result = min(result, i + j - 2);
      }
    }
  }
  cout << result << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, n)                                                              \
  for (int i = 0; i < n; i++)                                                  \
    ;
using namespace std;
typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  ll result = N - 1;
  for (ll i = 1; i <= sqrt(N); i++) {
    if (N % i == 0) {
      result = min(result, i + (N / i) - 2);
    }
  }
  cout << result << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
#define ios                                                                    \
  ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed
int main() {
  ios;
  ll n;
  cin >> n;
  int ans = 1;
  for (int i = 1; i * i <= n; ++i)
    if (n % i == 0)
      ans = i;
  cout << (n / ans + ans - 2) << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
#define ios                                                                    \
  ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed
int main() {
  ios;
  ll n;
  cin >> n;
  ll ans = 1;
  for (ll i = 1; i * i <= n; ++i)
    if (n % i == 0)
      ans = i;
  cout << (n / ans + ans - 2) << '\n';
  return 0;
}
Problem p02881 (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;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (int i = 1; i * i < n; i++) {
    if (n % i != 0)
      continue;
    ll j = n / i;
    ans = min(ans, i + j - 2);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    ll j = n / i;
    ans = min(ans, i + j - 2);
  }
  cout << ans << endl;
  return 0;
}