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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <functional>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i, n) for (int i = 0; i < n; i++)
#define fro(i, j, n) for (int i = j; i < n; i++)
#define ifr(i, n) for (int i = n - 1; i >= 0; i--)

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


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <functional>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i, n) for (int i = 0; i < n; i++)
#define fro(i, j, n) for (int i = j; i < n; i++)
#define ifr(i, n) for (int i = n - 1; i >= 0; i--)

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

Buggy submission (status: Runtime Error):
/* Simplicity and Goodness */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

void my_dbg() { cout << endl; }
template <typename Arg, typename... Args> void my_dbg(Arg A, Args... B) {
  cout << ' ' << A;
  my_dbg(B...);
}
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int N = 2e5 + 2;

void solve() {
  ll n, m;
  lscn(n);
  lscn(m);

  ll g = 1;

  for (ll i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      if ((i * n <= m) and ((m - (i * n)) % i == 0))
        g = max(g, i);

      ll d2 = n / i;

      if (((d2 * n) <= m) and ((m - (d2 * n)) % d2 == 0))
        g = max(g, d2);
    }
  }

  lprin(g);
}

int main() {
  int t = 1;
  // scn(t);

  while (t--) {
    solve();
  }
  return 0;
}

Fixed submission:
/* Simplicity and Goodness */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

void my_dbg() { cout << endl; }
template <typename Arg, typename... Args> void my_dbg(Arg A, Args... B) {
  cout << ' ' << A;
  my_dbg(B...);
}
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int N = 2e5 + 2;

void solve() {
  ll n, m;
  lscn(n);
  lscn(m);

  ll g = 1;

  for (ll i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      if ((i * n <= m) and ((m - (i * n)) % i == 0))
        g = max(g, i);

      ll d2 = m / i;

      if (((d2 * n) <= m) and ((m - (d2 * n)) % d2 == 0))
        g = max(g, d2);
    }
  }

  lprin(g);
}

int main() {
  int t = 1;
  // scn(t);

  while (t--) {
    solve();
  }
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P2;
#define fi first
#define se second
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

signed main() {
  int n, m;
  cin >> n >> m;
  for (int i = 450000000; i >= 1; i--) {
    if (i * (n - 1) >= m)
      continue;
    int x = i * (n - 1);
    int p = m - x;
    if (__gcd(p, i) == i) {
      cout << i << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P2;
#define fi first
#define se second
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> v;
  for (int i = 1; i * i <= m; i++) {
    if (m % i)
      continue;
    v.push_back(i);
    if (i * i != m)
      v.push_back(m / i);
  }

  sort(v.begin(), v.end(), greater<int>());

  for (int j = 0; j < v.size(); j++) {
    int i = v[j];
    // cout<<i<<endl;
    if (i * (n - 1) >= m)
      continue;
    int x = i * (n - 1);
    int p = m - x;
    if (__gcd(p, i) == i) {
      cout << i << endl;
      return 0;
    }
  }
}
Problem p03241 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define repall(i, arr) for (auto &i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T> void print(const vector<vector<T>> matrix);
template <typename T> void print(const vector<T> vec);
template <typename Arg> void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T> using pq = priority_queue<T>;
template <typename T> using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  int max = m / n;

  for (int i = 1; i <= m; i++) {
    if (m % i == 0 and m / i <= max) {
      print(m / i);
      break;
    }
  }

  return 0;
}

//---------------------------------------------
template <typename T> void print(const vector<vector<T>> matrix) {
  repall(vec, matrix) print(vec);
}
template <typename T> void print(const vector<T> vec) {
  unsigned int len = vec.size();
  rep(i, len - 1) cout << vec[i] << ' ';
  cout << vec[len - 1] << '\n';
}
template <typename Arg> void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
  cout << head << " ";
  print(args...);
}


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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define repall(i, arr) for (auto &i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T> void print(const vector<vector<T>> matrix);
template <typename T> void print(const vector<T> vec);
template <typename Arg> void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T> using pq = priority_queue<T>;
template <typename T> using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  int max = m / n;

  for (int i = max; i >= 1; i--) {
    if (m % i == 0) {
      print(i);
      break;
    }
  }

  return 0;
}

//---------------------------------------------
template <typename T> void print(const vector<vector<T>> matrix) {
  repall(vec, matrix) print(vec);
}
template <typename T> void print(const vector<T> vec) {
  unsigned int len = vec.size();
  rep(i, len - 1) cout << vec[i] << ' ';
  cout << vec[len - 1] << '\n';
}
template <typename Arg> void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
  cout << head << " ";
  print(args...);
}
Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, b) for (i = 0; i < b; ++i)
#define repp(i, a, b) for (i = a; i < b; ++i)
#define per(i, n) for (i = n - 1; i >= 0; i--)
#define endl "\n"
#define pb push_back
typedef long long int lli;
const lli mod = 1000000007;
typedef vector<lli> vi;
typedef pair<lli, lli> pi;
#define mp make_pair
#define pb push_back
int main() {
  // ios_base::sync_with_stdio(false);
  // cin.tie(NULL);
  lli n, t, i, k, j, f, g, m;
  string s;
  vi v;
  map<lli, lli> mm;
  map<lli, lli>::iterator it;
  cin >> n >> m;
  g = m / n;
  per(i, g) {
    if (m % i == 0) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, b) for (i = 0; i < b; ++i)
#define repp(i, a, b) for (i = a; i < b; ++i)
#define per(i, n) for (i = n - 1; i >= 0; i--)
#define endl "\n"
#define pb push_back
typedef long long int lli;
const lli mod = 1000000007;
typedef vector<lli> vi;
typedef pair<lli, lli> pi;
#define mp make_pair
#define pb push_back
int main() {
  // ios_base::sync_with_stdio(false);
  // cin.tie(NULL);
  lli n, t, i, k, j, f, g, m;
  string s;
  vi v;
  map<lli, lli> mm;
  map<lli, lli>::iterator it;
  cin >> n >> m;
  g = m / n;
  for (i = g; i > 0; i--) {
    if (m % i == 0) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
// #include <iomanip>
// #include <algorithm>
// #include <numeric>
// #include <queue>
// #include <stack>
#include <math.h>
// #include <vector>
// #include <string>
typedef long long LL;
using namespace std;

int main() {
  LL n;
  LL m;
  LL ans;
  LL ans_l = 1;
  LL ans_h;
  LL tmp;
  cin >> n >> m;
  ans_h = m;

  tmp = (LL)sqrt(m);
  if (m / n < tmp) {
    tmp = m / n;
  }
  for (int i = 2; i <= tmp; i++) {
    if (m % i == 0 && i > ans_l) {
      ans_l = i;
    }
  }
  tmp = (LL)sqrt(m);
  if (m / n > tmp) {
    tmp = m / n;
  }
  if (tmp >= n) {
    for (int i = n; i <= tmp; i++) {
      if (m % i == 0 && i < ans_h) {
        ans_h = i;
      }
    }
  }
  ans_h = m / ans_h;
  ans = max(ans_l, ans_h);
  cout << ans << endl;
}


Fixed submission:
#include <iostream>
// #include <iomanip>
// #include <algorithm>
// #include <numeric>
// #include <queue>
// #include <stack>
#include <math.h>
// #include <vector>
// #include <string>
typedef long long LL;
using namespace std;

int main() {
  LL n;
  LL m;
  LL ans;
  LL ans_l = 1;
  LL ans_h;
  LL tmp;
  cin >> n >> m;
  ans_h = m;

  tmp = (LL)sqrt(m);
  if (m / n < tmp) {
    tmp = m / n;
  }
  for (int i = 2; i <= tmp; i++) {
    if (m % i == 0 && i > ans_l) {
      ans_l = i;
    }
  }
  tmp = (LL)sqrt(m);
  if (tmp >= n) {
    for (int i = n; i <= tmp; i++) {
      if (m % i == 0 && i < ans_h) {
        ans_h = i;
      }
    }
  }
  ans_h = m / ans_h;
  ans = max(ans_l, ans_h);
  cout << ans << endl;
}
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 ans = 0;
  while (1) {
    if (m % n == 0) {
      ans = m / n;
      break;
    }
    n++;
  }
  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 ans = 1;
  for (int i = 1; i * i <= m; i++) {
    if (m % i)
      continue;
    if (i >= n)
      ans = max(ans, m / i);
    if (m / i >= n)
      ans = max(ans, i);
  }
  cout << ans << endl;
}
Problem p03241 (C++)

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}

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

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}

void solve() {
  int N, M;
  cin >> N >> M;
  int ans = 0;
  if (N == 1) {
    cout << M << endl;
    return;
  }
  for (int i = 1; i * N <= M; i++) {
    if ((M - i * N) % i == 0) {
      ans = i;
    }
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}
Problem p03241 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  for (ll i = 1; i <= m; i++) {
    ll t = m / i;
    if (m % i == 0 and n * t <= m) {
      cout << t << endl;
      return 0;
    }
  }
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  for (ll i = m / n; i >= 1; i--) {
    if (m % i == 0 and n * i <= m) {
      cout << i << 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 < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF(1 << 30);

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

  int ans = M / N;

  while (ans > 1) {
    int mul = N;
    while (ans * mul < M) {
      mul++;
    }
    if (ans * mul == M)
      break;
    ans--;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF(1 << 30);

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

  int ans = M / N;

  while (ans > 1) {
    // int mul = N;
    int mul = M / ans - 1;
    while (ans * mul < M) {
      mul++;
    }
    if (ans * mul == M)
      break;
    ans--;
  }

  cout << ans << endl;

  return 0;
}
Problem p03241 (C++)

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

typedef long long ll;

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> div = divisor(m);
  sort(div.begin(), div.end());
  auto t = *lower_bound(div.begin(), div.end(), n);
  cout << m / t << endl;
}

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

typedef long long ll;

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> div = divisor(m);
  sort(div.begin(), div.end());
  auto t = *lower_bound(div.begin(), div.end(), n);
  cout << m / t << endl;
}
Problem p03241 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int ans = 0;
  for (int i = 1; i <= M / N; ++i) {
    if (M % i == 0) {
      ans = max(ans, i);
    }
  }
  cout << ans << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int ans = 0;
  if (N == 1) {
    cout << M << endl;
    return 0;
  }
  for (int i = 1; i <= M / N; ++i) {
    if (M % i == 0) {
      ans = max(ans, i);
    }
  }
  cout << ans << endl;
}
Problem p03241 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N, M;
  cin >> N >> M;
  int max = 0;
  for (int i = 1; i <= M / N; i++) {
    if (M % i == 0 && M % i <= N) {
      max = i;
    }
  }
  cout << max << endl;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N, M;
  cin >> N >> M;
  int max = 0;
  if (M % N == 0) {
    cout << M / N << endl;
    return 0;
  }
  for (int i = 1; i <= M / N; i++) {
    if (M % i == 0 && M % i <= N) {
      max = i;
    }
  }
  cout << max << endl;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <climits>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <deque>   // deque
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <map> // map
#include <math.h>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ll long long
vector<ll> to[1000005];
int main() {
  ll a, b, c, d;
  cin >> a >> b;
  for (ll i = b; i > 0; i--) {
    if (b % i == 0 && b / i >= a) {
      cout << i;
      return 0;
    }
  }
}


Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <climits>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <deque>   // deque
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <map> // map
#include <math.h>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ll long long
vector<ll> to[1000005];
int main() {
  ll a, b, c, d;
  cin >> a >> b;
  for (ll i = b / a; i > 0; i--) {
    if (b % i == 0 && b / i >= a) {
      cout << i;
      return 0;
    }
  }
}
Problem p03241 (C++)

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

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


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = m; i >= 1; i--) {
    if (m % i == 0) {
      if (m / i >= n) {
        cout << i << endl;
        return 0;
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FOR_EQ(i, a, b) for (int i = (a); i <= (b); ++i)
#define FOR_RE(i, a, b) for (int i = (a); i > (b); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep_eq(i, n) FOR_EQ(i, 0, n)
#define rep_re(i, n) FOR_RE(i, n, 0)

#define WHITE 1 // （未訪問）
#define GRAY                                                                   \
  2 // （訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3 // （訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) // 10^21
int M[N][N];            // 隣接行列
int color[N];

// 1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
// 上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector> DVector;
int n;

// 配列の表示
void printArray(int array[], int n) {
  rep(i, n) {
    if (i)
      cout << " ";
    cout << array[i];
  }
  cout << endl;
}

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

  int m;
  cin >> n >> m;
  ll gcd;
  ll tmp;

  rep_re(i, m) {
    if (m % i == 0) {
      gcd = i;
      tmp = gcd * n;
      if (tmp <= m) {
        // cout << tmp << endl;
        cout << gcd << endl;
        return 0;
      }
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
// #include <mylib.h>
using namespace std;
// cin.sync_with_stdio(false);

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FOR_EQ(i, a, b) for (int i = (a); i <= (b); ++i)
#define FOR_RE(i, a, b) for (int i = (a); i > (b); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep_eq(i, n) FOR_EQ(i, 0, n)
#define rep_re(i, n) FOR_RE(i, n, 0)

#define WHITE 1 // （未訪問）
#define GRAY                                                                   \
  2 // （訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3 // （訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) // 10^21
int M[N][N];            // 隣接行列
int color[N];

// 1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
// 上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector> DVector;
int n;

// 配列の表示
void printArray(int array[], int n) {
  rep(i, n) {
    if (i)
      cout << " ";
    cout << array[i];
  }
  cout << endl;
}

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

  int m;
  cin >> n >> m;
  ll gcd;
  ll tmp;
  ll d = m / n;
  rep_re(i, d) {
    if (m % i == 0) {
      gcd = i;
      tmp = gcd * n;
      if (tmp <= m) {
        // cout << tmp << endl;
        cout << gcd << endl;
        return 0;
      }
    }
  }
}
Problem p03241 (C++)

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

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
int R(int Cx, int Cy, int x, int y) { return abs(x - Cx) + abs(y - Cy); }
int main(void) {
  int N, M, ans;
  cin >> N >> M;
  if (N == 1)
    ans = M;
  else if (N == 2 && M % 2 == 0)
    ans = M / 2;
  for (long int n = 1; n <= M / N + 2; n++) {
    if (M % n == 0 && M / n >= N)
      ans = n;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
int R(int Cx, int Cy, int x, int y) { return abs(x - Cx) + abs(y - Cy); }
int main(void) {
  int N, M, ans;
  cin >> N >> M;
  if (N == 1)
    ans = M;
  else if (N == 2 && M % 2 == 0)
    ans = M / 2;
  else if (N == 3 && M % 3 == 0)
    ans = M / 3;
  else {
    for (long int n = 1; n <= M / N + 2; n++) {
      if (M % n == 0 && M / n >= N)
        ans = n;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define mod (ll)(1e9 + 7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define fi first
#define se second
#define pb push_back

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  for (ll i = m; i > 0; i--) {
    if (m % i == 0) {
      if (m / i >= n) {
        cout << i << endl;
        return 0;
      }
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define mod (ll)(1e9 + 7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define fi first
#define se second
#define pb push_back

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  for (ll i = m / n; i > 0; i--) {
    if (m % i == 0) {
      if (m / i >= n) {
        cout << i << endl;
        return 0;
      }
    }
  }

  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 > 0; i--) {
    if (M % i == 0 && M / i >= N) {
      cout << i << endl;
      break;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
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: Time Limit Exceeded):
using namespace std;

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

typedef pair<int, int> ii;
typedef vector<int> vi;

int n, m;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

signed main() {
  scanf("%d%d", &n, &m);
  int mx = (m / n) + 1;
  int ans = 1, mod;
  int s = sqrt(m) + 1.;
  if (n == 1)
    printf("%d\n", m);
  else if (m % n == 0)
    printf("%d\n", m / n);
  else if (mx <= 70000000) {
    for (int i = 2; i < mx; i++) {
      mod = m - (i * (n - 1));
      ans = max(ans, gcd(mod, i));
    }
    printf("%d\n", ans);
  } else {
    for (int i = 2; i < s; i++) {
      if (m % i == 0) {
        if (i < mx)
          ans = max(i, ans);
        if (m / i < mx)
          ans = max(m / i, ans);
      }
    }
    printf("%d\n", ans);
  }
}


Fixed submission:
using namespace std;

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

typedef pair<int, int> ii;
typedef vector<int> vi;

int n, m;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

signed main() {
  scanf("%d%d", &n, &m);
  int mx = (m / n) + 1;
  int ans = 1, mod;
  int s = sqrt(m) + 1.;
  if (n == 1)
    printf("%d\n", m);
  else if (m % n == 0)
    printf("%d\n", m / n);
  else if (mx <= 50000000) {
    for (int i = 2; i < mx; i++) {
      mod = m - (i * (n - 1));
      ans = max(ans, gcd(mod, i));
    }
    printf("%d\n", ans);
  } else {
    for (int i = 2; i < s; i++) {
      if (m % i == 0) {
        if (i < mx)
          ans = max(i, ans);
        if (m / i < mx)
          ans = max(m / i, ans);
      }
    }
    printf("%d\n", ans);
  }
}
Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

vector<ll> frac(ll n) {
  vector<ll> res;
  res.clear();
  for (ll i = 2LL; i * i <= n; ++i) {
    if (n % i == 0LL) {
      res.push_back(i);
      if (i * i < n) {
        res.push_back(n / i);
      } // end if
    }   // end if
  }     // end for

  sort(ALL(res));

  return res;
}

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

  ll N, M;
  cin >> N >> M;

  vector<ll> f = frac(M);

  int ind1 = lower_bound(ALL(f), M / N) - f.begin();
  int ind2 = upper_bound(ALL(f), M / N) - f.begin();

  ll res = 0LL;
  if (ind1 == ind2) { // M / N より大きい
    res = f[ind1 - 1];
  } else { // M / N に等しい
    res = f[ind1];
  } // end if

  cout << res << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

vector<ll> frac(ll n) {
  vector<ll> res;
  res.clear();
  for (ll i = 1LL; i * i <= n; ++i) {
    if (n % i == 0LL) {
      res.push_back(i);
      if (i * i < n) {
        res.push_back(n / i);
      } // end if
    }   // end if
  }     // end for

  sort(ALL(res));

  return res;
}

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

  ll N, M;
  cin >> N >> M;

  vector<ll> f = frac(M);

  int ind1 = lower_bound(ALL(f), M / N) - f.begin();
  int ind2 = upper_bound(ALL(f), M / N) - f.begin();

  ll res = 0LL;
  if (ind1 == ind2) { // M / N より大きい
    res = f[ind1 - 1];
  } else { // M / N に等しい
    res = f[ind1];
  } // end if

  cout << res << endl;

  return 0;
}
Problem p03241 (C++)

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

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

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

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

int main() {
  // K(a1+a2+…aN)=M
  // M/K>=N&&M%K=0
  int N, K;
  cin >> N >> K;
  for (int i = K; i >= 1; i--) {
    if (K % i == 0 && K / i >= N) {
      cout << i;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;

int main() {
  // K(a1+a2+…aN)=M
  // M/K>=N&&M%K=0
  int N, K;
  cin >> N >> K;
  for (int i = K / N; i >= 1; i--) {
    if (K % i == 0 && K / i >= N) {
      cout << i;
      return 0;
    }
  }
}
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

  ll N, M;
  cin >> N >> M;

  vector<ll> divisors;

  for (ll i = 1; i <= M; ++i) {
    if (M % i == 0) {
      if (M / i < i)
        break;
      if (M / i == i) {
        divisors.push_back(i);
        break;
      }

      divisors.push_back(i);
      divisors.push_back(M / i);
    }
  }

  ll ans = 0;
  ll tmp = M / N;
  for (auto &d : divisors) {
    if (d <= tmp) {
      chmax(ans, d);
    }
  }

  cout << ans << endl;

  // system("pause");
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

  ll N, M;
  cin >> N >> M;

  vector<ll> divisors;

  for (ll i = 1; i <= sqrt(M); ++i) {
    if (M % i == 0) {
      if (M / i < i)
        break;
      if (M / i == i) {
        divisors.push_back(i);
        break;
      }

      divisors.push_back(i);
      divisors.push_back(M / i);
    }
  }

  ll ans = 0;
  ll tmp = M / N;
  for (auto &d : divisors) {
    if (d <= tmp) {
      chmax(ans, d);
    }
  }

  cout << ans << endl;

  // system("pause");
}
Problem p03241 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  int ma = m / n;
  int sum = 0;
  int ans = -1;
  for (int j = ma; j > 0; j--) {
    sum = 0;
    sum += j * n;
    if (sum > m)
      continue;
    else if (sum <= m) {
      while (sum < m) {
        sum += j;
      }
    }
    if (sum == m) {
      ans = j;
      break;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int ma = m / n;
  int sum = 0;
  int ans = -1;
  for (int j = ma; j > 0; j--) {
    if (m % j == 0) {
      ans = j;
      break;
    }
  }
  cout << ans << endl;
}
Problem p03241 (C++)

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

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

  if (m % n == 0) {
    cout << m / n;
    return 0;
  }
  int res = 1;
  for (int i = 2; i <= m; i++) {
    if (m % i == 0 && m / i >= n) {
      res = max(res, i);
    }
  }

  cout << res;
}

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

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

  if (m % n == 0) {
    cout << m / n;
    return 0;
  }
  int res = 1;
  for (int i = 2; m / i >= n; i++) {
    if (m % i == 0) {
      res = max(res, i);
    }
  }

  cout << res;
}
Problem p03241 (C++)

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

int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    int ans = 0;
    int t = m / n;
    for (int i = 1; i <= t; i++) {
      if (m / i >= n && m % i == 0)
        ans = max(ans, i);
    }
    printf("%d\n", ans);
  }
}

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

int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    int ans = 0;
    if (m % n == 0)
      ans = m / n;
    else {
      int t = m / n;
      for (int i = 1; i <= t; i++) {
        if (m % i == 0 && i <= m / n)
          ans = max(ans, i);
      }
    }
    printf("%d\n", ans);
  }
}
Problem p03241 (C++)

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#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 = 0;
  for (int i = 1; i * n <= m; i++) {
    if (m % i == 0) {
      ans = i;
    }
  }
  cout << ans << endl;
}

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#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 = 0;

  if (n == 1) {
    cout << m << endl;
    return 0;
  }
  for (int i = 1; i * n <= m; i++) {
    if (m % i == 0) {
      ans = i;
    }
  }
  cout << ans << endl;
}
Problem p03241 (C++)

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

int sumf(int m) {
  int r = 0;
  for (int i = 1; i < m + 1; i++)
    r += i;
  return r;
}
int main() {
  int p, q;
  cin >> p >> q;
  int m = 0;
  for (int i = 1; i <= q / p; i++) {
    if (q % i == 0)
      m = i;
  }
  cout << m << endl;
  return 0;
}

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

int sumf(int m) {
  int r = 0;
  for (int i = 1; i < m + 1; i++)
    r += i;
  return r;
}
int main() {
  int p, q;
  cin >> p >> q;
  int m = 0;
  if (p != 1) {
    for (int i = 1; i <= q / p; i++) {
      if (q % i == 0)
        m = i;
    }
  } else {
    m = q;
  }
  cout << m << endl;
  return 0;
}
Problem p03241 (Python)

Buggy submission (status: Time Limit Exceeded):
# a1 + a2 + a3 ... + an = M
# ai の 最大公約数をDとする
# ai = xi * D　のはず。 D * x0 + D * x1 ... + D * xn = M
# まとめて D(x1 + x2 + .... + xn) = M
# 変形し、D = M / (x1 + x2 + .... + xn)
# (x1 + ... xn) = K とすると、Kを最小化するとDが最大化する
# M / K が割り切れる必要があるので、KはMの約数のいずれか
# K >= N。なぜなら xi >= 1 なので、Kは最低でも数字の個数 N になる
# つまり、約数のうちで N 以上の最初の値が K になる
# ex: 3 14
# 14 の約数 {1, 2, 7}
# K >= N なので、　K >= 3
# K = 7 で確定。つまり D = M/K = 2 でAnswer

N, M = map(int, input().split())
for i in range(1, M + 1):
    if M % i == 0 and i >= N:
        print(M // i)
        break


Fixed submission:
# a1 + a2 + a3 ... + an = M
# ai の 最大公約数をDとする
# ai = xi * D　のはず。 D * x0 + D * x1 ... + D * xn = M
# まとめて D(x1 + x2 + .... + xn) = M
# 変形し、D = M / (x1 + x2 + .... + xn)
# (x1 + ... xn) = K とすると、Kを最小化するとDが最大化する
# M / K が割り切れる必要があるので、KはMの約数のいずれか
# K >= N。なぜなら xi >= 1 なので、Kは最低でも数字の個数 N になる
# つまり、約数のうちで N 以上の最初の値が K になる
# ex: 3 14
# 14 の約数 {1, 2, 7}
# K >= N なので、　K >= 3
# K = 7 で確定。つまり D = M/K = 2 でAnswer

N, M = map(int, input().split())
M_ROOT = int(M**0.5)
k = M
for i in range(1, M_ROOT + 1):
    if M % i == 0:
        if i >= N:
            print(M // i)
            exit()
        d = M // i
        if d < k and d >= N:
            k = d
print(M // k)
Problem p03241 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())

if N == 1:
    print(M)
else:
    ans = 1
    for g in range(1, int(M**0.5) + 1):
        if M % g == 0 and M / g >= N:
            ans = g
print(ans)


Fixed submission:
N, M = map(int, input().split())

ans = 1
for g in range(1, int(M**0.5) + 1):
    if M % g == 0 and M / g >= N:
        ans = max(ans, g)

    if M % g == 0:
        g2 = M // g
        if M % g2 == 0 and M / g2 >= N:
            ans = max(ans, g2)
print(ans)
Problem p03241 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define range(i, n, m) for (int i = n; i < m; i++)
#define rrange(i, n, m) for (int i = n - 1; i = > m; i--)
#define MOD 1000000007;

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

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

  ll N, M;
  cin >> N >> M;

  rrep(i, M + 1) {
    if (M % i == 0 && M / i >= N) {
      cout << dec << i;
      break;
    }
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define range(i, n, m) for (int i = n; i < m; i++)
#define rrange(i, n, m) for (int i = n - 1; i = > m; i--)
#define MOD 1000000007;

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

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

  ll N, M;
  cin >> N >> M;

  rrep(i, M / N + 1) {
    if (M % i == 0 && M / i >= N) {
      cout << dec << i;
      break;
    }
  }

  return 0;
}
Problem p03241 (C++)

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans;
  cin >> n >> m;
  if (n == 1) {
    cout << m;
    return 0;
  }
  for (int i = 1; i <= m / n; ++i) {
    if (m % i == 0 && m / i >= n)
      ans = i;
  }
  cout << ans;
  return 0;
}