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

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

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define forn(i, n) for (int i = 0; i < n; i++)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rforn(i, n) for (int i = n; i >= 0; i--)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int search;
  cin >> search;

  bool done = false;
  for (int i = 1; i < 10 && !done; i++) {
    if (search % i == 0 && (search / i) <= 9) {
      done = true;
    }
  }
  if (done) {
    cout << "Yes"
         << "\n";
  } else {
    cout << "No\n";
  }

  return 0;
}

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

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define forn(i, n) for (int i = 0; i < n; i++)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rforn(i, n) for (int i = n; i >= 0; i--)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int search;
  cin >> search;

  bool done = false;
  for (int i = 1; i < 10 && !done; i++) {
    if (search % i == 0 && (search / i) <= 9) {
      done = true;
    }
  }
  if (done) {
    cout << "Yes"
         << "\n";
  } else {
    cout << "No\n";
  }

  return 0;
}
Problem p02880 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
// const ll MOD = ;
ll mod(ll A, ll M) { return (A % M + M) % M; }
const ll INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll divceil(ll A, ll B) { return (A + (B - 1)) / B; }
ll myctoi(char C) { return C - '0'; }
char myitoc(ll N) { return '0' + N; }
#define FINALANS(A)                                                            \
  {                                                                            \
    cout << (A) << '\n';                                                       \
    exit(0);                                                                   \
  }

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

  vector<bool> ok(100, false);
  for (ll i = 1; i <= 9; i++) {
    for (ll j = 1; j <= 9; j++) {
      ok.at(i * j) = true;
    }
  }
  cout << ((ok.at(N)) ? "Yes" : "No") << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
// const ll MOD = ;
ll mod(ll A, ll M) { return (A % M + M) % M; }
const ll INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll divceil(ll A, ll B) { return (A + (B - 1)) / B; }
ll myctoi(char C) { return C - '0'; }
char myitoc(ll N) { return '0' + N; }
#define FINALANS(A)                                                            \
  {                                                                            \
    cout << (A) << '\n';                                                       \
    exit(0);                                                                   \
  }

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

  vector<bool> ok(1000, false);
  for (ll i = 1; i <= 9; i++) {
    for (ll j = 1; j <= 9; j++) {
      ok.at(i * j) = true;
    }
  }
  cout << ((ok.at(N)) ? "Yes" : "No") << endl;
}
Problem p02880 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  int a;
  cin >> a;
  for (int i = 0; i <= 9; i++) {
    if (a % i == 0 && a / i <= 9 && a / i >= 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  int a;
  cin >> a;
  for (int i = 1; i <= 9; i++) {
    if (a % i == 0 && a / i <= 9 && a / i >= 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p02880 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
#define ff(ii, nn, mm) for (int ii = nn; ii < mm; ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
  int n;
  cin >> n;
  int a = 0;
  ff(i, 0, 10) {
    a = n / i;
    if (a < 10 && n % i == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
#define ff(ii, nn, mm) for (int ii = nn; ii < mm; ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
  int n;
  cin >> n;
  int a = 0;
  ff(i, 1, 10) {
    a = n / i;
    if (a < 10 && n % i == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p02880 (C++)

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

int main() {

  int n;
  int a[101] = {0};
  cin >> n;
  for (int i = 0; i < 9; i++) {
    for (int j = 0; i < 9; j++) {
      a[(i + 1) * (j + 1) - 1]++;
    }
  }

  if (a[n - 1])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

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

int main() {

  int n;
  int a[101] = {0};
  cin >> n;
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      a[(i + 1) * (j + 1) - 1]++;
    }
  }

  if (a[n - 1])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p02880 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <string>

using namespace std;

int main() {
  int n;

  scanf("%d", &n);

  int i;

  int j;

  bool canflag = false;
  for (i = 1; i = 9; i++) {
    for (j = 1; j = 9; j++) {
      if (n % i == j)
        canflag = true;
    }
  }

  if (canflag == true)
    printf("Yes");
  else
    printf("No");
}

Fixed submission:
#include <cstdio>
#include <string>

using namespace std;

int main() {
  int n;

  scanf("%d", &n);

  int i;

  int j;

  bool canflag = false;
  for (i = 1; i <= 9; i++) {
    for (j = 1; j <= 9; j++) {
      if (i * j == n)
        canflag = true;
    }
  }

  if (canflag == true)
    printf("Yes");
  else
    printf("No");
}
Problem p02880 (C++)

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

using namespace std;

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

  int num = 0;
  for (int i = 1; i < 100; i++) {
    if (N != i && N % i == 0) {
      num = N / i;
    }
  }

  if (num <= 9 && N / num <= 9) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

using namespace std;

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

  int num = 0;
  for (int i = 1; i <= 9; i++) {
    if (N % i == 0) {
      num = N / i;
    }
  }

  if (num <= 9 && N / num <= 9) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02880 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string ans = "No\n";
  for (int i = 0; i < 10; i++) {
    if (N % i == 0 && N / i < 10) {
      ans = "Yes\n";
      break;
    }
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string ans = "No\n";
  for (int i = 1; i < 10; i++) {
    if (N % i == 0 && N / i < 10) {
      ans = "Yes\n";
      break;
    }
  }
  cout << ans;
}
Problem p02880 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n + 1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<bool>> name((h), vector<bool>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)                                                                  \
  cerr << "[";                                                                 \
  REPI(itr, v) { cerr << *itr << (itr != --v.end() ? ", " : ""); }             \
  cerr << "]" << endl

signed main() {
  int N;
  cin >> N;
  vector<int> v(100);
  FOR1(x, 9) {
    FOR1(y, 9) { v.at(x * y) = true; }
  }
  cout << (v.at(N) ? "Yes" : "No") << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n + 1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<bool>> name((h), vector<bool>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)                                                                  \
  cerr << "[";                                                                 \
  REPI(itr, v) { cerr << *itr << (itr != --v.end() ? ", " : ""); }             \
  cerr << "]" << endl

signed main() {
  int N;
  cin >> N;
  vector<int> v(105);
  FOR1(x, 9) {
    FOR1(y, 9) { v.at(x * y) = true; }
  }
  cout << (v.at(N) ? "Yes" : "No") << endl;
}
Problem p02880 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i, s, e) for (i = s; i < e; i++)
#define ms(arr, val) memset(arr, val, sizeof(arr))
using namespace std;

const int mxn = 2e5 + 1;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("outputs.txt", "w", stdout);
#endif
  int t = 1;
  //  cin>>t;
  int tt = 1;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++) {
      if (n % i == 0) {
        int a = n / i;
        if (a <= 9) {
          cout << "Yes";
          return 0;
        }
      }
    }
    cout << "No";
    // cout<<"Case #"<<tt<<": ";
    // tt++;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i, s, e) for (i = s; i < e; i++)
#define ms(arr, val) memset(arr, val, sizeof(arr))
using namespace std;

const int mxn = 2e5 + 1;

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

  int t = 1;
  //  cin>>t;
  int tt = 1;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++) {
      if (n % i == 0) {
        int a = n / i;
        if (a <= 9) {
          cout << "Yes";
          return 0;
        }
      }
    }
    cout << "No";
    // cout<<"Case #"<<tt<<": ";
    // tt++;
  }
  return 0;
}
Problem p02880 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define ll long long
#define itn int
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 1, n)
#define SORT(V) sort((V).begin(), (V).end())
#define REVERSE(V) reverse((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;

int main() {
  int N;
  cin >> N;
  bool CAN = false;

  for (int i = 1; i < 10; ++i) {
    for (int j = 1; i < 10; ++j) {
      if (i * j == N)
        CAN = true;
    }
  }

  if (CAN)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define ll long long
#define itn int
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 1, n)
#define SORT(V) sort((V).begin(), (V).end())
#define REVERSE(V) reverse((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;

int main() {
  int N;
  cin >> N;
  bool CAN = false;

  for (int i = 1; i < 10; ++i) {
    for (int j = 1; j < 10; ++j) {
      if (i * j == N)
        CAN = true;
    }
  }

  if (CAN)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02880 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  int a = 0, N;
  cin >> N;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      while (N == i * j) {
        a++;
      }
    }
  }
  if (a == 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  int a = 0, N;
  cin >> N;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (N == i * j) {
        a++;
      }
    }
  }
  if (a == 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}
Problem p02880 (C++)

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

int main() {
  int N = 81;
  int a[N];
  rep(i, N) {
    rep(j, N) { a[N * i + j] = (i + 1) * (j + 1); }
  }
  int tf = 0;
  int x;
  cin >> x;
  rep(i, N * N) {
    if (x == a[i]) {
      tf = 1;
    }
  }
  if (tf == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
  int N = 9;
  int a[N * N];
  rep(i, N) {
    rep(j, N) { a[N * i + j] = (i + 1) * (j + 1); }
  }
  int tf = 0;
  int x;
  cin >> x;
  rep(i, N * N) {
    if (x == a[i]) {
      tf = 1;
    }
  }
  if (tf == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02880 (Python)

Buggy submission (status: Runtime Error):
n = int(input().split())

a = []
for i in range(1, 10):
    for j in range(1, 10):
        a.append(i * j)

if n in a:
    print("Yes")
else:
    print("No")


Fixed submission:
n = int(input())

a = []
for i in range(1, 10):
    for j in range(1, 10):
        a.append(i * j)

if n in a:
    print("Yes")
else:
    print("No")
Problem p02880 (Python)

Buggy submission (status: Runtime Error):
N = int(input())

for i in range(1, 10):
    if N % i == 0 and N / i <= 9:
        print("Yes")
        exit(1)
print("No")


Fixed submission:
N = int(input())

for i in range(1, 10):
    if N % i == 0 and N / i <= 9:
        print("Yes")
        exit()
print("No")
Problem p02880 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
if n > 81:
    print("No")
else:
    is_ok = False
    for x in range(1, 10):
        if n % x == 0 and n // x <= 9:
            is_ok = True
            break

if is_ok:
    print("Yes")
else:
    print("No")


Fixed submission:
n = int(input())
if n > 81:
    print("No")
else:
    is_ok = False
    for x in range(1, 10):
        if n % x == 0 and n // x <= 9:
            is_ok = True
            break
    if is_ok:
        print("Yes")
    else:
        print("No")
Problem p02880 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int n;

  cin >> n;

  bool flag = false;

  for (int i = 1; i < 100; i++) {
    for (int k = 1; k < 100; i++) {
      if (n == (i * k)) {
        flag = true;
      }
    }
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n;

  cin >> n;

  bool flag = false;

  for (int i = 1; i < 10; i++) {
    for (int k = 1; k < 10; k++) {
      if (n == (i * k)) {
        flag = true;
      }
    }
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(void) {
  ll n;
  cin >> n;
  ll mn = LLONG_MAX;
  for (ll i = 1; i <= n / 2; i++) {
    if (n % i == 0) {
      ll a = i - 1, b = n / i - 1;
      mn = min(mn, a + b);
    }
  }
  cout << mn << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(void) {
  ll n;
  cin >> n;
  ll mn = LLONG_MAX;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ll a = i - 1, b = n / i - 1;
      mn = min(mn, a + b);
    }
  }
  cout << mn << endl;
  return 0;
}
Problem p02881 (C++)

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

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

  return 0;
}

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

int main() {
  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);
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02881 (C++)

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

#define REP(i, s, N) for (int i = s; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

ll ans = 0;

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

  REP(i, 1, N / 2 + 1) {
    if (N % i == 0) {
      if (N / i - i >= 0) {
        ans = i + N / i - 2;
      } else {
        break;
      }
    }
  }

  cout << ans << endl;
  return 0;
}

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

#define REP(i, s, N) for (int i = s; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

ll ans = 0;

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

  REP(i, 1, sqrt(N) + 1) {
    if (N % i == 0) {
      if (N / i - i >= 0) {
        ans = i + N / i - 2;
      } else {
        break;
      }
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

int main() {
  long long int i, j, v, count = 1000000000000;
  long long int a = 0;

  cin >> v;

  for (i = 1; i <= v / 2; i++) {

    if (v % i == 0) {
      a = 0;
      a += (v / i - 1 + i - 1);
      count = min(count, a);
    }
  }
  cout << count << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

int main() {
  long long int i, j, v, count = 1000000000000;
  long long int a = 0;

  cin >> v;

  for (i = 1; i * i <= v; i++) {

    if (v % i == 0) {
      a = 0;
      a += (v / i - 1 + i - 1);
      count = min(count, a);
    }
  }
  cout << count << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#define ll long long
const int N = 1e6 + 10;
using namespace std;
ll n;

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

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#define ll long long
const int N = 1e6 + 10;
using namespace std;
ll n;

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#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 ans = n - 1;

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

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#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 ans = n - 1;

  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      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;
typedef long long ll;

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

  for (int a = 1; a * a <= N; a++) {
    if (N % a == 0)
      res = min(res, a + N / a - 2);
  }
  cout << res;
  return 0;
}

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

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

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

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

int main() {
  long n, a, b, res;
  cin >> n;

  res = 1000000000000;

  for (long i = 2; i < n / 2; ++i) {

    if (n % i == 0) {
      a = n / i;

      if (res > a + i - 2) {
        res = a + i - 2;
      } else if (res == a + i - 2) {
        break;
      }
    }
  }
  if (a < 1)
    res = n - 1;

  cout << res << endl;
}

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

int main() {
  long n, a, b, res;
  cin >> n;

  res = 1000000000000;

  for (long i = 2; i <= sqrt(n); ++i) {

    if (n % i == 0) {
      a = n / i;

      if (res > a + i - 2) {
        res = a + i - 2;
      } else if (res == a + i - 2) {
        break;
      }
    }
  }
  if (a < 1)
    res = n - 1;

  cout << res << 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++)
typedef long long ll;
int main() {

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

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

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

Fixed submission:
#include <bits/stdc++.h>
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)
      ans = min(ans, i + n / i - 2);
  cout << ans << endl;
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  long int a, b;
  cin >> a;
  long int min = 0, t;

  for (int i = 1; i < a / 2 + 1; ++i) {
    if (a % i == 0) {
      t = i - 1 + a / i - 1;
      if (min == 0 || min > t) {
        min = t;
      }
    }
  }

  cout << min << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  long int a, b;
  cin >> a;
  long int min = 0, t;

  for (int i = 1; i <= sqrt(a); ++i) {

    if (a % i == 0) {
      t = i - 1 + a / i - 1;
      if (min == 0 || min > t) {
        min = t;
      }
    }
  }

  cout << min << 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;
  while (cin >> n) {
    ll maxn = n - 1;
    for (ll i = n / 2; i > 1; i--) {
      for (ll j = 2; j <= n / i; j++) {
        if (i * j == n) {
          maxn = min(i + j - 2, maxn);
        }
      }
    }
    cout << maxn << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n;
  while (cin >> n) {
    ll maxn = n - 1;
    for (ll i = sqrt(n); i > 1; i--) {
      if (i * (n / i) == n) {
        maxn = min(i + (n / i) - 2, maxn);
        break;
      }
    }
    cout << maxn << endl;
  }
}
Problem p02881 (C++)

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

int main(void) {
  queue<long> que;
  long N;
  cin >> N;
  long min = N;
  for (long i = 1; i < sqrt(N); i++) {
    for (long j = i; j <= N; j++) {
      if (N == i * j) {
        que.push(i + j - 2);
      }
    }
  }
  while (!que.empty()) {
    if (min > que.front()) {
      min = que.front();
    }
    que.pop();
  }
  cout << min << endl;
}


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

int main(void) {
  queue<long> que;
  long N;
  cin >> N;
  long min = N;
  for (long i = 1; i <= sqrt(N); i++) {
    if (!(N % i)) {
      que.push(i + N / i - 2);
    }
  }
  while (!que.empty()) {
    if (min > que.front()) {
      min = que.front();
    }
    que.pop();
  }
  cout << min << endl;
}
Problem p02881 (C++)

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

using namespace std;

int main() {

  long n;

  cin >> n;

  long ans = -1;
  long i, j;
  for (i = 1; i <= n; i++) {
    if (n % i == 0) {
      j = n / i;
      if (ans != -1) {
        if (ans > i - 1 + j - 1) {
          ans = i - 1 + j - 1;
        }
      } else {
        ans = i - 1 + j - 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {

  long n;

  cin >> n;

  long ans = -1;
  long i, j;
  for (i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      j = n / i;
      if (ans != -1) {
        if (ans > i - 1 + j - 1) {
          ans = i - 1 + j - 1;
        }
      } else {
        ans = i - 1 + j - 1;
      }
    }
  }
  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 ans = n - 1;
  for (long long i = 1; i <= n / 2; i++)
    if (n % i == 0)
      ans = min(ans, i + (n / i) - 2);
  cout << ans << endl;
  return 0;
}


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

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

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long i = 1; i <= n; i++)
using ll = long long;
int main() {
  ll n, ans;
  cin >> n;
  ans = n;
  rep(i, sqrt(n)) {
    if (n % i == 0) {
      ans = min(i + n / i - 2, ans);
    }
  }
  cout << ans << 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 < (int)(n); i++)
typedef long long ll;
int main() {
  // ifstream in("data1.txt");
  // cin.rdbuf(in.rdbuf());
  ll N;
  ll ans = 1e12;
  cin >> N;
  for (ll i = 1; i * 1 <= N; i++) {
    if (N % i == 0) {
      ans = min(ans, i + N / i - 2);
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  // ifstream in("data1.txt");
  // cin.rdbuf(in.rdbuf());
  ll N;
  ll ans = 1e12;
  cin >> N;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ans = min(ans, i + N / i - 2);
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define ll long long

using namespace std;

int main() {
  ll n;
  cin >> n;
  bool in = false;
  for (int i = sqrt(n); i <= n; i++) {
    if (n % i == 0) {
      cout << n / i + i - 2;
      break;
    }
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define ll long long

using namespace std;

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

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

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

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

bool is_Prime(long long N) {
  if (N == 1)
    return false;
  for (long long i = 2; i * i <= N; i++) {
    if (N % i == 0)
      return false;
  }
  return true;
}

int main() {
  long long N;
  cin >> N;
  if (is_Prime(N)) {
    cout << N - 1 << endl;
    return 0;
  }
  long long ans = 0;

  for (int i = 1; i * i <= N; i++) {
    if (N % i == 0) { // 割り切れるとき
      long long a = i;
      long long b = N / a;
      ans = a + b -
            2; // 1,1スタートなので(下に1,右に1移動してからスタート)2を引く
    }
  }
  cout << ans << endl;
}

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

bool is_Prime(long long N) {
  if (N == 1)
    return false;
  for (long long i = 2; i * i <= N; i++) {
    if (N % i == 0)
      return false;
  }
  return true;
}

int main() {
  long long N;
  cin >> N;
  if (is_Prime(N)) {
    cout << N - 1 << endl;
    return 0;
  }
  long long ans = 0;

  for (long long i = 1; i * i <= N; i++) {
    if (N % i == 0) { // 割り切れるとき
      long long a = i;
      long long b = N / a;
      ans = a + b -
            2; // 1,1スタートなので(下に1,右に1移動してからスタート)2を引く
    }
  }
  cout << ans << endl;
}
Problem p02881 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
factor = []
tmp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
    while tmp % i == 0:
        factor.append(i)
        tmp //= i
if tmp != 1:
    factor.append(tmp)
w = len(factor)
if w == 0:
    factor.append(n)
    w = 1
if w == 1:
    print(n - 1)
else:
    ans = 1000000000000
    for i in range(1, 2**w // 2):
        f2 = [1, 1]
        for j in range(w):
            f2[i & (2**j) == 0] *= factor[j]
        ans = min(ans, sum(f2) - 2)
        if ans < n**0.5 * 2:
            break
    print(ans)


Fixed submission:
n = int(input())
ans = 1000000000000
for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        a = i
        b = n // i
        ans = min(ans, a + b - 2)
print(ans)
Problem p02881 (C++)

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

signed main() {
  unsigned long long int N;
  cin >> N;
  unsigned long long int count = 0;
  for (int i = 0; i < sqrt(N) + 1; i++) {
    if (N % i == 0) {
      if (count == 0) {
        count = i + N / i - 2;
      } else {
        count = min(count, i + N / i - 2);
      }
    }
  }
  cout << count << endl;
}


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

signed main() {
  unsigned long long int N;
  cin >> N;
  unsigned long long int count = 0;
  for (int i = 1; i < sqrt(N) + 1; i++) {
    if (N % i == 0) {
      if (count == 0) {
        count = i + N / i - 2;
      } else {
        count = min(count, i + N / i - 2);
      }
    }
  }
  cout << count << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
using namespace std;

int main() {
  long long n;
  cin >> n;
  long long a, b;
  a = 1;
  b = 1;
  long long shortest = 100000000000000;
  r_rep_ll(i, 1, (n / 2 + 1)) {
    if (n % i == 0) {
      b = n / i;
      shortest = min(shortest, i + b - 2);
    }
  }
  // while (a*b <= 1000000000000){
  //   if(a*b == n){
  //     shortest = a + b - 2;
  //     break;
  //   }else if(a*b > n){
  //     break;
  //   }
  //   b += 1;
  // }
  cout << shortest << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
using namespace std;

int main() {
  long long n;
  cin >> n;
  long long a, b;
  a = 1;
  b = 1;
  long long shortest = 100000000000000;
  r_rep_ll(i, 1, pow(n, 0.5) + 1) {
    if (n % i == 0) {
      b = n / i;
      shortest = min(shortest, i + b - 2);
    }
  }
  // while (a*b <= 1000000000000){
  //   if(a*b == n){
  //     shortest = a + b - 2;
  //     break;
  //   }else if(a*b > n){
  //     break;
  //   }
  //   b += 1;
  // }
  cout << shortest << 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 ll = long long;
using namespace std;
using P = pair<int, int>;

int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (ll i = 0; 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 ll = long long;
using namespace std;
using P = pair<int, int>;

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;
}
Problem p02881 (C++)

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

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

  cout << ans << endl;
  return 0;
}

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

using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ans = n - 1;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      ans = min(ans, (n / i) + i - 2);
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>

#define INF 10010010010
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

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

  ll ans = 1000000000005;

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


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>

#define INF 10010010010
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

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

  ll ans = 1000000000005;

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

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

typedef signed long long ll;
typedef long double ld;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) x.begin(), x.end()

#define DEBUG

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

  ll min = (ll)1e18;
  for (int i = 1; i < n; i++) {
    if ((n % i) == 0 && ((n / i) + i - 2) < min) {
      // cout << i << "\t" << n/i << endl;
      min = (i + (n / i)) - 2;
    }
  }
  cout << min << endl;
  return 0;
}


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

typedef signed long long ll;
typedef long double ld;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) x.begin(), x.end()

#define DEBUG

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

  ll min = (ll)1e18;
  for (ll i = 1; i <= sqrt(n); i++) {
    if ((n % i) == 0 && ((n / i) + i - 2) < min) {
      // cout << i << "\t" << n/i << endl;
      min = (i + (n / i)) - 2;
    }
  }
  cout << min << endl;
  return 0;
}
Problem p02881 (C++)

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

using namespace std;

typedef long long int int64;

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

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

using namespace std;

typedef long long int int64;

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

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

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


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

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

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

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;
}

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

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;
}
Problem p02881 (C++)

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

int main() {
  ll n, ans = 1e12 + 7;
  cin >> n;

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

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

int main() {
  ll n, ans = 1e12 + 7;
  cin >> n;

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

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <cstdint>
#include <iostream>
#include <limits>

int main() {
  uint64_t target;
  std::cin >> target;

  uint64_t sq_target = std::sqrt(target);
  uint64_t ans = std::numeric_limits<uint64_t>::max();

  for (uint64_t i = 1; i <= sq_target; ++i) {
    for (uint64_t j = i;; ++j) {
      if (i * j >= target) {
        if (i * j == target)
          ans = std::min(ans, (i + j - 2));
        break;
      }
    }
  }
  std::cout << ans << std::endl;
}

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

int main() {
  uint64_t target;
  std::cin >> target;

  uint64_t sq_target = std::sqrt(target);
  uint64_t ans = std::numeric_limits<uint64_t>::max();

  for (uint64_t i = 1; i <= sq_target; ++i) {
    if (target % i == 0) {
      ans = std::min(ans, i + (target / i) - 2);
    }
  }
  std::cout << ans << std::endl;
}
Problem p02881 (C++)

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

// #define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i < n; ++i)
#define EPS (1e-7)
#define gearup                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
ll MOD = 1000000007;
const long long INF = 1LL << 60;
// cout<<fixed<<setprecision(10);

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> void debug(T v) {
  rep(i, v.size()) cout << v[i] << " ";
  cout << endl;
}

signed main() {
  // gearup;
  ll n;
  cin >> n;
  // 素数判定
  bool is_prime = true;
  ll res = 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      is_prime = false;
      res = i;
    }
  }
  if (!is_prime)
    cout << res - 1 + n / res - 1 << endl;
  else
    cout << n - 1 << endl;
}


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

// #define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i < n; ++i)
#define EPS (1e-7)
#define gearup                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
ll MOD = 1000000007;
const long long INF = 1LL << 60;
// cout<<fixed<<setprecision(10);

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> void debug(T v) {
  rep(i, v.size()) cout << v[i] << " ";
  cout << endl;
}

signed main() {
  // gearup;
  ll n;
  cin >> n;
  // 素数判定
  bool is_prime = true;
  ll res = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      is_prime = false;
      res = i;
    }
  }
  if (!is_prime)
    cout << res - 1 + n / res - 1 << endl;
  else
    cout << n - 1 << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
int main() {

  long long n;
  cin >> n;
  long long mi = n - 1;
  for (int i = 1; i < n + 1; i++) {
    if (n % i == 0) {
      mi = min(mi, (i - 1) + (n / i - 1));
    }
  }
  cout << mi;
}

Fixed submission:
#include <algorithm>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
int main() {

  long long n;
  cin >> n;
  long long mi = n - 1;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      mi = min(mi, (i - 1) + (n / i - 1));
    }
  }
  cout << mi;
}