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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;
  if (m % n == 0) {
    cout << m / n;
    return 0;
  }
  int k = m / n;
  int l = m % n;
  int a = 1;
  while (true) {
    if ((n * a + l) % (k - a) == 0)
      break;
    a++;
  }
  cout << k - a;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;
  if (m % n == 0) {
    cout << m / n;
    return 0;
  }
  if (m / n == 1) {
    cout << 1;
    return 0;
  }
  int k = m / n;
  int l = m % n;
  int a = 1;
  while (true) {
    if ((n * a + l) % (k - a) == 0)
      break;
    a++;
  }
  cout << k - a;
  return 0;
}
Problem p03241 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;

vector<pair<ll, ll>> factorize(ll N) {
  vector<pair<ll, ll>> res;
  ll n = N;
  for (ll p = 2; p * p <= n; p++) {
    if (N % p != 0)
      continue;
    int count = 0;
    while (N % p == 0) {
      count++; // pで割れる回数をカウント
      N /= p;
    }
    res.push_back(make_pair(p, count));
  }
  if (N != 1)
    res.push_back(make_pair(N, 1)); // 最終的にNが素数のとき
  return res;
}

vl getFactors(ll N) {
  vector<pair<ll, ll>> f = factorize(N);
  vl res;
  res.push_back(1);
  for (int i = 0; i < f.size(); i++) {
    int s = res.size();
    for (int j = 0; j < s; j++)
      for (int k = 0; k < f[i].second; k++) {
        res.push_back(res[j] * pow(f[i].first, k + 1));
      }
  }
  sort(res.begin(), res.end());
  return res;
}

int main() {
  ll N, M;
  cin >> N >> M;
  vl factors = getFactors(M);
  for (int i = factors.size() - 1; i >= 0; i--) {
    if (M / i >= N) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;

vector<pair<ll, ll>> factorize(ll N) {
  vector<pair<ll, ll>> res;
  ll n = N;
  for (ll p = 2; p * p <= n; p++) {
    if (N % p != 0)
      continue;
    int count = 0;
    while (N % p == 0) {
      count++; // pで割れる回数をカウント
      N /= p;
    }
    res.push_back(make_pair(p, count));
  }
  if (N != 1)
    res.push_back(make_pair(N, 1)); // 最終的にNが素数のとき
  return res;
}

vl getFactors(ll N) {
  vector<pair<ll, ll>> f = factorize(N);
  vl res;
  res.push_back(1);
  for (int i = 0; i < f.size(); i++) {
    int s = res.size();
    for (int j = 0; j < s; j++)
      for (int k = 0; k < f[i].second; k++) {
        res.push_back(res[j] * pow(f[i].first, k + 1));
      }
  }
  sort(res.begin(), res.end());
  return res;
}

int main() {
  ll N, M;
  cin >> N >> M;
  vl factors = getFactors(M);
  for (int i = factors.size() - 1; i >= 0; i--) {
    if (M / factors[i] >= N) {
      cout << factors[i] << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03241 (C++)

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

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  llong n, m;
  cin >> n >> m;
  if (m % n == 0) {
    cout << m / n << endl;
    return 0;
  }

  llong ans = 0;
  for (int i = m; i > 0; --i) {
    if (m % i == 0 && n * i <= m) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  llong n, m;
  cin >> n >> m;
  if (m % n == 0) {
    cout << m / n << endl;
    return 0;
  }

  llong ans = 0;
  for (llong i = m; i > 0; --i) {
    if (n * i <= m) {
      if (m % i == 0) {
        ans = i;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03241 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  int ans = 1;
  for (int i = 1; i <= M; i++) {
    if (M % i == 0 && M / i >= N)
      ans = i;
  }
  cout << ans << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int ans = 1;
  for (int i = 1; i * i <= M; i++) {
    if (M % i == 0) {
      if (M / i >= N)
        ans = max(ans, i);
      if (i >= N)
        ans = max(ans, M / i);
    }
  }
  cout << ans << endl;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main(void) {

  long long int n, m;
  cin >> n >> m;

  long long int ans = 1;

  if (m % n == 0) {
    cout << m / n << endl;
    return 0;
  } else {

    for (long long int i = 2; i <= m; i++) {
      if (m % i == 0) {
        if (m / i > n)
          ans = i;
      }
    }
  }

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

Fixed submission:
#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main(void) {

  long long int n, m;
  cin >> n >> m;

  long long int ans = 1;

  if (m % n == 0) {
    cout << m / n << endl;
    return 0;
  } else {

    for (long long int i = 2; i <= m; i++) {
      if (m % i == 0) {
        if (m / i > n)
          ans = i;
      }

      if (m / i < n)
        break;
    }
  }

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

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

#define DEBUG

// 素数列を作る
// N: 上限
// v: 出力先
void GetPrimes(int N, vector<int> &v) {
  v = vector<int>();
  int c = 1;
  while (c < N) {
    c++;
    bool flag = true;
    int d = (int)sqrt(c);
    for (int i = 0; i < v.size(); i++) {
      if (c % v[i] == 0) {
        flag = false;
        break;
      }
      if (d < v[i])
        break;
    }
    if (flag)
      v.push_back(c);
  }
}

// 素因数分解を行う
// N: 対象
// p: 素数セット(GetPrimesで取得)
// v: 導かれた指数部
// [return]: 割り切れない場合の残り, 失敗すると-1を返す
int64_t Factorize(int64_t N, const vector<int> &p, vector<int> &v) {
  if (p.back() < sqrt(N))
    return -1;
  for (int i = 0; N != 1 && i < p.size(); i++) {
    v.push_back(0);
    while (N % p[i] == 0) {
      N /= p[i];
      v[i]++;
    }
  }
  return N;
}

int64_t N, M, L, ans = 0;
vector<int> P;
vector<int> F;

void recursive(int k, int64_t n) {
  if (M < n * N)
    return;
  if (k == -1) {
    ans = max(n, ans);
    return;
  }
  int64_t tmp = 1;
  for (int i = 0; i <= F[k]; i++) {
    recursive(k - 1, n * tmp);
    tmp *= P[k];
  }
}

int main() {
#ifdef DEBUG
  std::ifstream in("/home/share/inputf.in");
  std::cin.rdbuf(in.rdbuf());
#endif
  cin >> N >> M;
  GetPrimes(100000, P);
  Factorize(M, P, F);
  L = F.size();
  recursive(L - 1, 1);
  cout << ans << endl;
  return 0;
}

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

// 素数列を作る
// N: 上限
// v: 出力先
void GetPrimes(int N, vector<int> &v) {
  v = vector<int>();
  int c = 1;
  while (c < N) {
    c++;
    bool flag = true;
    int d = (int)sqrt(c);
    for (int i = 0; i < v.size(); i++) {
      if (c % v[i] == 0) {
        flag = false;
        break;
      }
      if (d < v[i])
        break;
    }
    if (flag)
      v.push_back(c);
  }
}

// 素因数分解を行う
// N: 対象
// p: 素数セット(GetPrimesで取得)
// v: 導かれた指数部
// [return]: 割り切れない場合の残り, 失敗すると-1を返す
int64_t Factorize(int64_t N, const vector<int> &p, vector<int> &v) {
  if (p.back() < sqrt(N))
    return -1;
  for (int i = 0; N != 1 && i < p.size(); i++) {
    v.push_back(0);
    while (N % p[i] == 0) {
      N /= p[i];
      v[i]++;
    }
  }
  return N;
}

int64_t N, M, L, ans = 0;
vector<int> P;
vector<int> F;

void recursive(int k, int64_t n) {
  if (M < n * N)
    return;
  if (k == -1) {
    ans = max(n, ans);
    return;
  }
  int64_t tmp = 1;
  for (int i = 0; i <= F[k]; i++) {
    recursive(k - 1, n * tmp);
    tmp *= P[k];
  }
}

int main() {
#ifdef DEBUG
  std::ifstream in("/home/share/inputf.in");
  std::cin.rdbuf(in.rdbuf());
#endif
  cin >> N >> M;
  GetPrimes(100000, P);
  Factorize(M, P, F);
  L = F.size();
  recursive(L - 1, 1);
  cout << ans << endl;
  return 0;
}
Problem p03241 (C++)

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


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int end = m / n;
  int ans = 1;
  vector<int> v;
  for (int i = 1; i * i <= m && i <= end; i++) {
    if (m % i == 0) {
      v.push_back(i);
      if (m / i <= end) {
        v.push_back(m / i);
      }
    }
  }
  for (auto e : v) {
    int tmp = m - (n - 1) * e;
    if (tmp % e == 0) {
      ans = max(ans, e);
    }
  }
  cout << ans << endl;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n, m, a;
  in2(n, m);
  rep2(i, 1, 210000000) {
    if (m % i == 0) {
      if (n * i <= m)
        a = max(a, i);
      if (n * (m / i) <= m)
        a = max(a, (m / i));
    }
  }
  out(a);
  memi;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n, m, a;
  in2(n, m);
  rep2(i, 1, 191000000) {
    if (m % i == 0) {
      if (n * i <= m)
        a = max(a, i);
      if (n * (m / i) <= m)
        a = max(a, (m / i));
    }
  }
  out(a);
  memi;
}
Problem p03241 (C++)

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

using namespace std;

int main() {
  int N, M;

  cin >> N >> M;
  // M/N以下のMの最大の約数dじゃね？
  // K=M/dとしたとき、K>=N
  // Kをd個の整数に分けるのはeasyじゃん
  // 間に合うかな

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

  cout << MAX << endl;
}

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

using namespace std;

int main() {
  int N, M;

  cin >> N >> M;
  // M/N以下のMの最大の約数dじゃね？
  // K=M/dとしたとき、K>=N
  // Kをd個の整数に分けるのはeasyじゃん
  // 間に合うかな

  int MAX = 1;
  for (int i = 1; i * i <= M; i++) {
    if (M % i != 0)
      continue;
    if (M / i <= M / N)
      MAX = max(M / i, MAX);
    else if (i <= M / N)
      MAX = max(MAX, i);
  }

  cout << MAX << endl;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n, m, a;
  in2(n, m);
  rep2(i, 1, 198000000) {
    if (m % i == 0) {
      if (n * i <= m)
        a = max(a, i);
      if (n * (m / i) <= m)
        a = max(a, (m / i));
    }
  }
  out(a);
  memi;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n, m, a;
  in2(n, m);
  rep2(i, 1, 185000000) {
    if (m % i == 0) {
      if (n * i <= m)
        a = max(a, i);
      if (n * (m / i) <= m)
        a = max(a, (m / i));
    }
  }
  out(a);
  memi;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return abs(a * b) / gcd(a, b); }
std::vector<bool> IsPrime;
void sieve(size_t max) {
  if (max + 1 > IsPrime.size())
    IsPrime.resize(max + 1, true);
  IsPrime[0] = false;
  IsPrime[1] = false;
  for (size_t i = 2; i * i <= max; ++i)
    if (IsPrime[i])
      for (size_t j = 2; i * j <= max; ++j)
        IsPrime[i * j] = false;
}
#define roundup(divisor, dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(), (x).end()
#define size_t ll
const int mod = 1000000007;
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
ll n, m;
ll ans = 0;
int main() {
  cin >> n >> m;
  for (size_t i = 1; i <= roundup(m, n); i++) {
    if (m % i == 0)
      ans = i;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return abs(a * b) / gcd(a, b); }
std::vector<bool> IsPrime;
void sieve(size_t max) {
  if (max + 1 > IsPrime.size())
    IsPrime.resize(max + 1, true);
  IsPrime[0] = false;
  IsPrime[1] = false;
  for (size_t i = 2; i * i <= max; ++i)
    if (IsPrime[i])
      for (size_t j = 2; i * j <= max; ++j)
        IsPrime[i * j] = false;
}
#define roundup(divisor, dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(), (x).end()
#define size_t ll
const int mod = 1000000007;
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
ll n, m;
ll ans = 0;
int main() {
  cin >> n >> m;
  for (ll i = 1; pow(i, 2) <= m; i++) {
    if (m % i != 0)
      continue;
    if (i <= m / n)
      ans = max(i, ans);
    if ((m / i) <= (m / n))
      ans = max(m / i, ans);
  }
  cout << ans << endl;
}
Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod = 1e9 + 7;

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> yk;
  for (int i = 1; i <= sqrt(m); i++) {
    if (m % i == 0) {
      yk.push_back(i);
      yk.push_back(m / i);
    }
  }
  sort(yk.begin(), yk.end());
  double ch = m / n;
  int ans = 0;
  for (int i = 0; yk[i] <= ch; i++) {
    ans = yk[i];
  }
  cout << ans << endl;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod = 1e9 + 7;

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> yk;
  for (int i = 1; i <= sqrt(m); i++) {
    if (m % i == 0) {
      yk.push_back(i);
      yk.push_back(m / i);
    }
  }
  sort(yk.begin(), yk.end());
  double ch = m / n;
  int ans = 0;
  for (int i = 0; yk[i] <= ch && i < yk.size(); i++) {
    ans = yk[i];
  }
  cout << ans << endl;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
// head
struct edge {
  int to, cap, rev, cost;
};
vector<edge> G[1000];
void add_edge(int from, int to, int cap, int cost = 0) {
  G[from].push_back(edge{to, cap, (int)G[to].size(), cost});
  G[to].push_back(edge{from, 0, (int)G[from].size() - 1, -cost});
}

int main() {
  int N, M;
  std::cin >> N >> M;
  int ans = 1;
  rep(i, 1, M / N + 1) {
    if (M % i == 0) {
      ans = i;
    }
  }
  std::cout << ans << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
// head
struct edge {
  int to, cap, rev, cost;
};
vector<edge> G[1000];
void add_edge(int from, int to, int cap, int cost = 0) {
  G[from].push_back(edge{to, cap, (int)G[to].size(), cost});
  G[to].push_back(edge{from, 0, (int)G[from].size() - 1, -cost});
}

int main() {
  int N, M;
  std::cin >> N >> M;
  int ans = 1;
  if (N == 1) {
    std::cout << M << '\n';
    exit(0);
  }
  rep(i, 1, M / N + 1) {
    if (M % i == 0) {
      ans = i;
    }
  }
  std::cout << ans << '\n';
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
int main() {
  int n, M, ans = 1;
  scanf("%d%d", &n, &M);
  for (int i = 2; i <= M / n; ++i) {
    if (M % i)
      continue;
    if (M / i >= n)
      ans = i;
  }
  printf("%d", ans);
  return 0;
}

Fixed submission:
#include <cstdio>
int main() {
  int n, M, ans = 1;
  scanf("%d%d", &n, &M);
  if (n == 1)
    return !printf("%d", M);
  for (int i = 2; i <= M / n; ++i) {
    if (M % i)
      continue;
    if (M / i >= n)
      ans = i;
  }
  printf("%d", ans);
  return 0;
}
Problem p03241 (C++)

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

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

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPP(i, n) for (int i = 1; i <= n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

ll gcd(ll x, ll y) {
  if (x < y)
    gcd(y, x);
  while (y > 0) {
    ll tmp = x % y;
    x = y;
    y = tmp;
  }
  return x;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  ll a = m / 2 + (m % 2), b = m / 2;
  ll ans = 0;
  while (ans == 0) {
    if (a % b == 0)
      ans = b;
    a += n - 1;
    --b;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPP(i, n) for (int i = 1; i <= n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

ll gcd(ll x, ll y) {
  if (x < y)
    gcd(y, x);
  while (y > 0) {
    ll tmp = x % y;
    x = y;
    y = tmp;
  }
  return x;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  ll a = m / n + m % n, b = m / n;
  ll ans = 0;
  while (ans == 0) {
    if (a % b == 0)
      ans = b;
    a += n - 1;
    --b;
  }
  cout << ans << endl;
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <utility> // pair
#include <vector>
#define MAX_N 100001
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REV(i, n) for (ll i = n - 1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 9e18;
ll n, m;

signed main() {
  cin >> n >> m;
  ll ret = 0;
  FOR(i, 1, m / n + 1) {
    if ((m - i * (n - 1)) % i == 0)
      ret = max(ret, i);
  }
  cout << ret << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <utility> // pair
#include <vector>
#define MAX_N 100001
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REV(i, n) for (ll i = n - 1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 9e18;
ll n, m;

signed main() {
  cin >> n >> m;
  ll ret = 0;
  // FOR(i, 1, m/n + 1){
  for (ll i = 1; i * i <= m; i++) {
    if (m - i * (n - 1) > 0) {
      if ((m - i * (n - 1)) % i == 0)
        ret = max(ret, i);
    }
    if (m - (m / i) * (n - 1) > 0) {
      if ((m - (m / i) * (n - 1)) % (m / i) == 0)
        ret = max(ret, (m / i));
    }
  }
  cout << ret << endl;
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

/*sortの仕方
 * ■ string s の場合
 * 昇順: sort(s.begin(), s.end())
 * 降順:  sort(s.rbegin(), s.rend())
 *
 * ■ int a[N] の場合
 * 昇順: sort(a, a+N)
 * 降順: 不明
 */

/*int alph2int(char character) {
    int x = character - 'a';
    return x;
}
*/

int main() {
  int N, M;
  cin >> N >> M;
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    if (M % i == 0) {
      if (N <= M / i) {
        ans = i;
      }
    }
  }

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

/*sortの仕方
 * ■ string s の場合
 * 昇順: sort(s.begin(), s.end())
 * 降順:  sort(s.rbegin(), s.rend())
 *
 * ■ int a[N] の場合
 * 昇順: sort(a, a+N)
 * 降順: 不明
 */

/*int alph2int(char character) {
    int x = character - 'a';
    return x;
}
*/

int main() {
  int N, M;
  cin >> N >> M;
  int ans = 0;
  if (N == 1) {
    cout << M << endl;
    return 0;
  }

  for (int i = 1; i <= M / 2; i++) {
    if (M % i == 0) {
      if (N <= M / i) {
        ans = i;
      }
    }
  }

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

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

#define INF 100100100
#define MOD 1000000007

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

struct edge {
  ll to, cost;
};

int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M;
  cin >> N >> M;
  ll ans = 1;
  for (ll i = 1; i <= M / N; i++) {
    if (M % i == 0 && M / i >= N)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}


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

#define INF 100100100
#define MOD 1000000007

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

struct edge {
  ll to, cost;
};

int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M;
  cin >> N >> M;
  ll ans = 1;
  ll B;
  for (ll i = 1; i * i <= M; i++) {
    B = M / i;
    if (M % i == 0) {
      if (i <= M / N)
        ans = max(ans, i);
      if (B <= M / N)
        ans = max(ans, B);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03241 (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() {

  int N, M;
  cin >> N >> M;
  int A = 1;
  int ans = 0;
  while (M > (N - 1) * A) {
    if ((M + A - N * A) % A == 0)
      ans = A;
    A++;
  }
  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() {

  int N, M;
  cin >> N >> M;
  int A = 1;
  int ans = 0;
  if (N == 1) {
    cout << M << endl;
    return 0;
  }
  while (M > (N - 1) * A) {
    if ((M + A - N * A) % A == 0)
      ans = A;
    A++;
  }
  cout << ans << endl;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 1;
  for (int i = 1; i * n <= m; i++) {
    if ((m - i * n) % i == 0)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 1;
  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      if (i <= m / n)
        ans = max(ans, i);
      if (i >= n)
        ans = max(ans, m / i);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03241 (C++)

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

using namespace std;

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

  for (int i = M; i >= 1; --i) {
    if (M % i == 0) {
      int k = M / i;
      if (k >= N) {
        cout << M / k << endl;
        return 0;
      }
    }
  }
}

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

using namespace std;

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

  for (int i = M / N + 1; i >= 1; --i) {
    if (M % i == 0) {
      int k = M / i;
      if (k >= N) {
        cout << M / k << endl;
        return 0;
      }
    }
  }
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll nCr(ll n, ll r) {
  if (r == 0 || r == n) {
    return 1;
  } else if (r == 1) {
    return n;
  }
  return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r) {
  r = n - r;
  ll ret = 1;
  for (ll i = n; i >= r + 1; i--)
    ret *= i;
  return ret;
}

//-----------------------ここから-----------
int main(void) {
  int n, m;
  cin >> n >> m;
  int ans = 1;
  for (int i = 2; i * n <= m; i++) {
    if (m % i == 0) {
      ans = i;
    }
  }
  cout << ans << endl;
}

Fixed submission:
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll nCr(ll n, ll r) {
  if (r == 0 || r == n) {
    return 1;
  } else if (r == 1) {
    return n;
  }
  return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r) {
  r = n - r;
  ll ret = 1;
  for (ll i = n; i >= r + 1; i--)
    ret *= i;
  return ret;
}

//-----------------------ここから-----------
int main(void) {
  int n, m;
  cin >> n >> m;
  int ans = 1;
  if (n == 1) {
    cout << m << endl;
    return 0;
  }
  for (int i = 2; i * n <= m; i++) {
    if (m % i == 0) {
      ans = i;
    }
  }
  cout << ans << endl;
}
Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, x) for (int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9 + 7;
const int n_max = 1e5 + 10;

int main() {
  ll n, m;
  cin >> n >> m;
  priority_queue<ll> pq;
  rep(i, sqrt(m)) {
    if (!i)
      continue;
    if (m % i == 0) {
      pq.push(i);
      pq.push(m / i);
    }
  }

  bool ok = true;
  ll ans = 0;
  while (ok) {
    ll temp = pq.top();
    pq.pop();
    if (n * temp <= m) {
      ans = temp;
      ok = false;
    }
  }

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

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, x) for (int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9 + 7;
const int n_max = 1e5 + 10;

int main() {
  ll n, m;
  cin >> n >> m;
  priority_queue<ll> pq;
  rep(i, sqrt(m) + 1) {
    if (!i)
      continue;
    if (m % i == 0) {
      pq.push(i);
      pq.push(m / i);
    }
  }

  bool ok = true;
  ll ans = 0;
  while (ok) {
    ll temp = pq.top();
    pq.pop();
    if (n * temp <= m) {
      ans = temp;
      ok = false;
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; i++)
#define rep3(i, n, m) for (ll i = n; i >= m; i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second
const ll INF = 1e18;
inline void chmax(ll &a, ll b) { a = max(a, b); }
inline void chmin(ll &a, ll b) { a = min(a, b); }

int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 1;
  rep2(i, 1, m) {
    if (m % i == 0 && (m / i) >= n)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; i++)
#define rep3(i, n, m) for (ll i = n; i >= m; i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second
const ll INF = 1e18;
inline void chmax(ll &a, ll b) { a = max(a, b); }
inline void chmin(ll &a, ll b) { a = min(a, b); }

int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 1;
  for (ll i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      ll j = m / i;
      if (j >= n)
        chmax(ans, i);
      if (i >= n)
        chmax(ans, j);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03241 (C++)

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

int main() {
  long long N, M;
  cin >> N >> M;
  long long number = 1;
  for (int i = M; i > sqrt(M) - 1; i--) {
    if (M % i == 0) {
      if (M >= i * N) {
        number = i;
        break;
      } else if (i >= N)
        number = M / i;
    }
  }
  cout << number << endl;
}


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

int main() {
  long long N, M;
  cin >> N >> M;
  long long number = 1;
  for (int i = M / N + 1; i >= 1; i--) {
    if (M % i == 0) {
      if (M >= i * N) {
        number = i;
        break;
      } else if (i >= N)
        number = M / i;
    }
  }
  cout << number << endl;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long N, M;
  cin >> N >> M;
  while (true) {
    if (M % N == 0)
      break;
    else if (M == N)
      break;
    else
      N++;
  }
  cout << M / N << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int ans, ansMax, temp;

  ansMax = M / N;

  for (ans = ansMax; ans > 0; --ans) {
    temp = M - ans * (N - 1);
    if ((temp % ans) == 0) {
      cout << ans << endl;
      return 0;
    }
  }

  return 0;
}

int main_failed() {
  int N, M;
  cin >> N >> M;
  while (true) {
    if (M % N == 0)
      break;
    else if (M == N)
      break;
    else
      N++;
  }
  cout << M / N << endl;

  return 0;
}
Problem p03241 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  while (m % n != 0)
    n++;
  cout << m / n << '\n';
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      if (n <= i)
        ans = max(ans, m / i);
      if (n <= m / i)
        ans = max(ans, i);
    }
  }
  cout << ans << '\n';
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef vector<vector<ll>> VVL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main() {
  int N, M;
  cin >> N >> M;
  while (M % N)
    N++;
  cout << M / N << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef vector<vector<ll>> VVL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main() {
  int N, M;
  cin >> N >> M;
  while (M % N and M / 2 >= N)
    N++;
  cout << M / N << endl;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define int64 long long
using namespace std;

int main() {
  int n, m, ans;
  cin >> n >> m;
  rep1(i, (m / n) + 1) {
    if (m % i == 0) {
      ans = i;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define int64 long long
using namespace std;

int main() {
  int n, m, ans;
  cin >> n >> m;
  if (n == 1) {
    ans = m;
  } else {
    rep1(i, (m / n) + 1) {
      if (m % i == 0) {
        ans = i;
      }
    }
  }
  cout << ans << endl;
}
Problem p03241 (C++)

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, m, sum, ans = 1;
  cin >> n >> m;
  ll l = 1, r = 1000000001LL, mid;
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (mid * n <= m) {
      l = mid;
    } else {
      r = mid;
    }
  }
  while (l > 0) {
    sum = m - n * l;
    if (sum % l == 0) {
      ans = l;
      break;
    } else {
      l--;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, m;
int main() {
  cin >> n >> m;
  for (int i = n; i <= m; i++) {
    if (m % i == 0) {
      cout << m / i << endl;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, m;
int main() {
  cin >> n >> m;
  for (int i = n; i <= m; i++) {
    if (m % i == 0) {
      cout << m / i << endl;
      return 0;
    } else if (i > m / 2) {
      cout << 1 << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03241 (C++)

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

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

  while (M % N != 0)
    N++;
  cout << M / N << endl;
}


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

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

  for (int i = M / N; i > 0; i--)
    if (M % i == 0) {
      cout << i << endl;
      break;
    }
}
Problem p03241 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;

  int ans = 1;
  for (int i = 1; i * i <= m; --i) {
    if (m % i == 0) {
      if (m / i >= n) {
        ans = max(ans, i);
      }

      if (m / (m / i) >= n) {
        ans = max(ans, m / i);
      }
    }
  }

  cout << ans << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;

  int ans = 1;
  for (int i = 1; i * i <= m; ++i) {
    if (m % i == 0) {
      if (m / i >= n) {
        ans = max(ans, i);
      }

      if (m / (m / i) >= n) {
        ans = max(ans, m / i);
      }
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9

using namespace std;
typedef long long ll;

int main() {
  ll n, m, ans;
  cin >> n >> m;

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

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9

using namespace std;
typedef long long ll;

int main() {
  ll n, m, ans;
  cin >> n >> m;
  for (ll i = 1; i * i <= m && i * n <= m; i++) {
    if (m % i == 0) {
      if ((m / i) * n <= m) {
        ans = max(ans, m / i);
      } else {
        ans = max(ans, i);
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;

ll N, M, ans = 1;
int main(void) {
  cin >> N >> M;
  FOR(i, 1, M / N + 1) {
    if (M % i != 0)
      continue;
    if (M / i >= N)
      ans = i;
    else
      break;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;

ll N, M, ans = 1;
int main(void) {
  cin >> N >> M;
  if (N == 1)
    ans = M;
  else {
    FOR(i, 1, M / N + 1) {
      if (M % i != 0)
        continue;
      if (M / i >= N)
        ans = i;
      else
        break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
#define vecout(V)                                                              \
  for (int i = 0; i < V.size(); i++) {                                         \
    cout << V[i] << endl;                                                      \
  }
typedef long long ll;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(void) {
  ll n, m;
  cin >> n >> m;
  vector<ll> v = divisor(m);
  int left = 0;
  int right = v.size();
  while (right - left > 1) {
    int mid = (left + right) / 2;
    if (v[mid] >= n)
      right = mid;
    else
      left = mid;
  }
  cout << m / v[right] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
#define vecout(V)                                                              \
  for (int i = 0; i < V.size(); i++) {                                         \
    cout << V[i] << endl;                                                      \
  }
typedef long long ll;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(void) {
  ll n, m;
  cin >> n >> m;
  vector<ll> v = divisor(m);
  if (n == 1) {
    cout << m << endl;
    return 0;
  }
  int left = 0;
  int right = v.size();
  while (right - left > 1) {
    int mid = (left + right) / 2;
    if (v[mid] >= n)
      right = mid;
    else
      left = mid;
  }
  cout << m / v[right] << endl;
}