text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; template <typename T> T in() { char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == '-') { ng = true; ch = getchar(); break; } if (ch >= '0' && ch <= '9') break; } while (1) { n = n * 10 + (ch - '0'); ...
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcnt(...
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 1; void solve() { long long int n, m, k, p = 0, q = 0, s = 0, c = 0, i, j; cin >> n >> k; if (k >= 4) s += 9 * n * (n - 1) * (n - 2) * (n - 3) / 24; if (k >= 3) s += 2 * n * (n - 1) * (n - 2) / 6; if (k >= 2) s += n * (n - 1) / 2; s...
#include <bits/stdc++.h> using namespace std; long long dp[1001][1001], d[5]; int n, k; int main() { cin >> n >> k; dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = 1; dp[i][i] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { dp[i][j] = dp[i - 1][j - 1] + dp[i - 1]...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long double PI = acos(-1); long long POWER[65]; void precompute() { POWER[0] = 1; for (int i = 1; i < 63; i++) POWER[i] = POWER[i - 1] << 1LL; } long long fastMul(long long a, long long b, long long mod) { long long res = 0; a %=...
#include <bits/stdc++.h> using namespace std; long long int n, k; long long int dr[5] = {1, 0, 1, 2, 9}; long long int ncr(long long int n, long long int r) { long long int ans = 1; for (long long int i = n - r + 1; i <= n; i++) { ans *= i; } for (long long int i = 1; i <= r; i++) { ans /= i; } retu...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; vector<long long> a(5); a[0] = 1; a[1] = 0; a[2] = n * (n - 1) / 2; a[3] = (n * (n - 1) * (n - 2) / 6) * 2; a[4] = (n * (n - 1) * (n - 2) * (n - 3...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; scanf("%d %d", &n, &k); ll ans = 0; if (k >= 4) { ans += 1LL * n * (n - 1) * (n - 2) * (n - 3) / 8LL...
#include <bits/stdc++.h> using namespace std; long long ncr(long long n, long long l) { long long r = n - l; if (l > r) swap(l, r); long long up = 1; for (long long i = r + 1; i <= n; i++) { up = up * i; } long long down = 1; for (long long i = 2; i <= l; i++) { down = down * i; } long long re...
#include <bits/stdc++.h> using namespace std; signed main() { long long n, k; cin >> n >> k; long long cnt2 = 1; long long cnt3 = 2; long long cnt4 = 9; long long ans = 1; if (k >= 2) ans += n * (n - 1) / 2 * cnt2; if (k >= 3) ans += n * (n - 1) * (n - 2) / 1 / 2 / 3 * cnt3; if (k >= 4) ans += n * (n ...
#include <bits/stdc++.h> using namespace std; long long nCr(long long n, long long r) { if (r == 0) return 1; long long i, fact = 1, ans = 1; for (i = 1; i <= r; i++) fact *= i; long long rr = n - r; while (n > rr) { ans *= n; n--; } return ans / fact; } int main() { ios_base::sync_with_stdio(fa...
#include <bits/stdc++.h> using namespace std; const int Inf = 1e9; int main() { ios::sync_with_stdio(0); int n, k; while (cin >> n >> k) { long long ans; if (k >= 1) { ans = 1; } if (k >= 2) { ans += n * (n - 1) / 2; } if (k >= 3) { ans += n * (n - 1) * (n - 2) / 3; }...
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846264; signed main() { long long n, k; cin >> n >> k; long long ans = 0; long long dear[5] = {0, 0, 1, 2, 9}; if (k == 1) { ans = 1; } if (k == 2) { ans = 1; ans += (n * (n - 1)) / 2; } if (k == 3) { an...
#include <bits/stdc++.h> using namespace std; int n, k; long long c(int a, int b) { long long res = 1; for (int i = 1; i <= b; ++i) { res = res * (a + 1 - i) / i; } return res; } int main() { scanf("%d%d", &n, &k); long long ans = 1; for (int i = 1; i <= k; ++i) { if (i == 2) { ans += c(n, 2...
#include <bits/stdc++.h> using namespace std; long long C(int n, int k) { long long res = 0; if (k == 2) return (n * (n - 1)) / 2; if (k == 3) { res = n * (n - 1); res = res * (n - 2); res = res / 6; } if (k == 4) { res = ((n) * (n - 1)) / 2; res = ((res) * (n - 2)) / 3; res = ((res) *...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int a[5], b[5], ans = 0, i; a[0] = 1; a[1] = 0; a[2] = ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; int k; cin >> n >> k; if (k == 1) cout << 1; else if (k == 2) cout << n * (n - 1) / 2 + 1; else if (k == 3) cout << n * (n - 1) * (n - 2) / 6 * 2 + n * (n - 1) / 2 + 1; else cout << n * (n - 1) * (n - 2) * (n - 3) / 24...
#include <bits/stdc++.h> using namespace std; long long power(long long b, long long exp, long long m) { long long ans = 1; b %= m; while (exp) { if (exp & 1) ans = (ans * b) % m; exp >>= 1; b = (b * b) % m; } return ans; } long long combi(int d, int l) { int k = d - l; unsigned long long ans1...
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; long long int ans_k(long long int k, long long int n) { if (k == 0) return 1; else if (k == 1) return 0; else if (k == 2) return ((n * (n - 1)) / (1 * 2)); else if (k == 3) return ((n * (n - 1) * (n - 2)) / (1 * 2 * 3)...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, ans = 1; scanf("%lld%lld", &n, &k); if (k >= 2) ans += (n * (n - 1)) >> 1; if (k >= 3) ans += (n * (n - 1) * (n - 2)) / 3; if (k == 4) ans += 3 * ((n * (n - 1) * (n - 2) * (n - 3)) >> 3); printf("%lld", ans); }
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; cin >> n >> k; long long ans = 0; if (k >= 1) ans++; if (k >= 2) ans += (n * (n - 1)) / 2; if (k >= 3) ans += (n * (n - 1) * (n - 2)) / 3; if (k >= 4) ans += ((n * (n - 1) * (n - 2) * (n - 3)) / 24) * 9; cout << ans; } int main...
#include <bits/stdc++.h> using namespace std; vector<long long int> derang(1002); vector<vector<long long int> > comb(1002); long long int assign(int n, int k) { if (n < 0 || k < 0) { return 0; } else { if (n >= k) { if (comb[n][k] == -1) { if (k == 0) { comb[n][k] = 1; } els...
#include <bits/stdc++.h> using namespace std; long long int derange[1005], factorial[6]; long long int derangements(long long int n) { if (n == 1) return 0; if (n == 2) return 1; if (n == 0) return 1; if (derange[n] != -1) return derange[n]; return derange[n] = (n - 1) * (derangements(n - 1) + derangements(n ...
#include <bits/stdc++.h> using namespace std; int f[5] = {1, 1, 2, 6, 24}; long long per(long n, long k) { long long j = 1; for (int i = n - k + 1; i <= n; i++) { j *= i; } return j / f[k]; } int main() { int i, j, n, k; cin >> n >> k; long long a = 1; int m[5] = {1, 0, 1, 2, 9}; for (i = k; i >= ...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; static const int _ = []() { ios::sync_with_stdio(false); cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }(); template <typename T, typename ...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); long long n; int k; cin >> n >> k; long long ans = 0; if (k >= 4) { ans += 9 * n * (n - 1) * (n - 2) * (n - 3) / 24; } if (k >= 3) { ans += 2 * n * (n - 1) * (n - 2) / 6; } if (k >= 2) ...
#include <bits/stdc++.h> using namespace std; long long n, k, all[10][10000], d = -3, a = 1; int main() { cin >> n >> k; for (long long i = 0; i < 1001; ++i) all[1][i] = 1; all[2][4] = 7; for (long long i = 5; i < 1001; ++i) all[2][i] = all[2][i - 1] + (i - 1LL); all[3][4] = 15; for (long long i = 5; i < 10...
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma comment(linker, "/STACK:10240000,10240000") using namespace std; const long long P = 1e9 + 7; long long mul(long long a, long long b) { long long ans = 0; for (; b; a = a * 2 % P, b >>= 1) if (b & 1) ans = (ans + a) % P; return ans; } long long qpow(lon...
#include <bits/stdc++.h> int abs(int); int main() { long long int n; long long int k; while (scanf("%I64d", &n) != EOF) { scanf("%I64d", &k); long long int ans = 0; for (long long int i = 1; i <= k; i++) { if (i == 1) { ans += 1; } if (i == 2) { ans += n * (n - 1) / 2...
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? "YES" : "NO"); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { assert(y >= 0); x += y; if (x >...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, k; cin >> n >> k; long long c = 0; if (k >= 1) c += 1; if (k >= 2) c += (n * (n - 1) / 2); if (k >= 3) c += (n * (n - 1) * (n - 2) / 3); if (k >= 4) c += (n * (n - 1) * (n - 2) * (n - 3) / 24) * 9; cout << c << endl; }
#include <bits/stdc++.h> using namespace std; int bico(int n, int k) { if (k == n || k == 0) return 1; else return bico(n - 1, k - 1) + bico(n - 1, k); } int main() { long long int n, k; cin >> n >> k; if (k == 1) { cout << "1"; } else if (k == 2) { cout << (n * (n - 1) / 2) + 1; } else if...
#include <bits/stdc++.h> using namespace std; const long long INF(0x3f3f3f3f3f3f3f3fll); const long long inf(0x3f3f3f3f); template <typename T> void read(T &res) { bool flag = false; char ch; while (!isdigit(ch = getchar())) (ch == '-') && (flag = true); for (res = ch - 48; isdigit(ch = getchar()); res =...
#include <bits/stdc++.h> using namespace std; long long int nck(long long int n, long long int k) { long long int ans = 1; for (int i = 0; i < k; i++) { ans = ans * (n - i); } for (int i = 1; i <= k; i++) { ans = ans / i; } return ans; } long long int nck2(long long int n, long long int k) { long ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, ans = 0; cin >> n >> k; if (k > 1) ans += (n * (n - 1)) / 2; if (k > 2) ans += (n * (n - 1) * (n - 2)) / 6 * 2; if (k > 3) ans += (n * (n - 1) * (n - 2) * (n - 3)) / 24 * 9; ans++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; long long C(int x, int y) { long long temp = 1; long long ans = 1; int y1 = y; while (y > 0) { temp *= x; x--; y--; } while (y1 > 0) { ans *= y1; y1--; } return temp / ans; } int main() { scanf("%d%d", &n, &k); long long tem...
#include <bits/stdc++.h> using namespace std; int n, k; int d[5]; long long int nCr(int x, int r) { long long int num = 1, den = 1; int rr = r; for (int i = 0; i < r; i++) { num *= x; den *= rr; x--; rr--; } return (num / den); } int main() { d[0] = 1, d[1] = 0, d[2] = 1, d[3] = 2, d[4] = 9;...
#include <bits/stdc++.h> using namespace std; inline void read(long long &x) { x = 0; long long f = 1; char c = getchar(); for (; c > '9' || c < '0'; c = getchar()) if (c == '-') f = -1; for (; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + c - '0'; x *= f; } const int N = 1005; long long n, m, ans =...
#include <bits/stdc++.h> using namespace std; int factor[5] = {0, 1, 1, 2, 9}; long long choose(int n, int k); int main() { int n, k; cin >> n >> k; long long ret = 1; for (int i = 2; i <= k; i++) ret += factor[i] * choose(n, i); cout << ret << '\n'; } long long choose(int n, int k) { long long ret = 1; f...
#include <bits/stdc++.h> using namespace std; long long d[5] = {1, 0, 1, 2, 9}; long long n, k; long long nck(long long x) { long long tmp; if (x == 0) return 1; if (x == 1) return n; else if (x == 2) { tmp = n * (n - 1); tmp = tmp / 2; } else if (x == 3) { tmp = n * (n - 1) * (n - 2); tmp...
#include <bits/stdc++.h> using namespace std; template <typename T, typename T1> ostream &operator<<(ostream &out, pair<T, T1> obj) { out << "(" << obj.first << ", " << obj.second << ")"; return out; } template <typename T, typename T1> ostream &operator<<(ostream &out, map<T, T1> cont) { typename map<T, T1>::con...
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const int inf = (int)1e9 + 7; const double eps = 1e-7; const double pi = 3.14159265359; const int N = (int)1e4; const int K = 4; long long n, k; long long dp[N][K]; signed main() { scanf("%lld%lld", &n, &k); if (k == 1) printf("...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, k; cin >> n >> k; long long int ans = 1, sum = 0; for (int i = 2; i <= k; i++) { if (i == 2) { ans += (n * (n - 1)) / 2; } if (i == 3) { ans += ((n * (n - 1) * (n - 2)) / 6) * 2; } if (i == 4) ans += ((...
#include <bits/stdc++.h> using namespace std; template <class A> void read(vector<A>& v); template <class A, size_t S> void read(array<A, S>& a); template <class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d = stod(t); } void read(long double& d) { string t; read(t); d = sto...
#include <bits/stdc++.h> using namespace std; long long com(int n, int r) { if (r > n / 2) r = n - r; long long ans = 1; for (int i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = 0; i <= m; i++) { int ar...
#include <bits/stdc++.h> using namespace std; long long MAX = 9223372036854775800; unsigned long long val(int n, int k) { unsigned long long num = 1; for (int i = 0; i < k; i++) { num *= (n - i); } for (int i = 1; i <= k; i++) { num /= i; } if (k == 3) { num *= 2; } else if (k == 4) { num ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, a, b; cin >> n >> a >> b; if (n == a + b) { cout << 1 << endl; return 0; } long long int val = 0; for (long long int i = 1; i < n; i++) { val = max(val, min(a / i, b / (n...
#include <bits/stdc++.h> using namespace std; long long int cons; long long int check(long long int a) { if (a >= cons) a %= cons; return a; } long long int check2(long long int a) { a %= cons; if (a < 0) a += cons; return a; } long long int GCD(long long int a, long long int b) { if (b == 0) return a; re...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "; "; err(++it, args...); } void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { cin >> x; } template <typename T, typename T0> void read(T &x, T0 &y) { cin >> x >> y; } template <typename T, typename T0, typename T1> void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; } template <typename T, typename T0, ty...
#include <bits/stdc++.h> using namespace std; int n, a, b, ans; int main() { scanf("%d %d %d ", &n, &a, &b); for (int x = 1; x <= min(a, b); x++) if ((a / x + b / x) >= n) ans = max(ans, x); cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; int i, j; for (i = min(a, b); i >= 1; i--) { for (j = 1; j < n; j++) { if (j * i <= a && (n - j) * i <= b) { cout << i << "\n"; return 0; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; cin >> n >> a >> b; int x = (a + b) / n; while ((((a / x + b / x)) < n) || a < x || b < x) x--; cout << x; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, mx = 0; cin >> n >> a >> b; for (int i = 1; i < n; i++) { int mn = min(a / i, b / (n - i)); if (mn > mx) mx = mn; } cout << mx << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, a, b; cin >> n >> a >> b; long long low = 1, high = min(a, b), ans = 0; while (low <= high) { long long mid = (low + high) / 2; long long x = a / mid; if (b >= mid * (n - x)) { ...
#include <bits/stdc++.h> using namespace std; int main() { int i, n, a, b, c, d; ios_base::sync_with_stdio(false); cin >> n >> a >> b; int ar[n - 1], j = 1, k = n - 1; for (i = 0; i < (n - 1); i++) { c = a / j; d = b / k; j++; k--; (c < d) ? (ar[i] = c) : (ar[i] = d); } sort(ar, ar + (...
#include <bits/stdc++.h> using namespace std; int n, a, b; bool ok(int t) { int take = t * n, fa = 0, fb = 0; if (take > a + b) return false; if (t > a || t > b) return false; if (a >= t) { int cnta = a / t; int cntb = b / t; if (cnta + cntb >= n) fa = 1; else fa = 0; } if (b >= ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, t, l, k, p, q, r, a, b, c, d, n1; long long int count = 0, count1 = 0, total = 0, ans = 0; long long int max1 = INT_MIN, min1 = INT_MAX; long long int temp = 0, temp1; ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(N...
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long i, j, k, n, m, ans = 0, sum = 0, a[100005] = {0}, mn = 2e9, mx = 0, cnt = 1, index = 0, x, y, z, tx, ty, tn; string s; cin >> n >> x >> y; for (...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; int ans = 0; for (int i = 1; i <= min(a, b); i++) { if (a / i + b / i >= n) ans = i; else break; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long c) { long long x = 1, y = a; while (b > 0) { if (b & 1) x = (x * y) % c; y = (y * y) % c; b /= 2; } return x % c; } int dx[] = {0, -1, 0, 1}; int dy[] = {-1, 0, 1, 0}; int dr[] = {1, 1, 0, -1, -1, -1, 0...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a, b; cin >> a >> b; int ans = 0; for (int i = 1; i <= n - 1; i++) ans = max(ans, min(a / i, b / (n - i))); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, max = 0; cin >> n >> a >> b; int i; int x, y, z, min, flag = 100; min = a + b; if (a + b == n) { max = 1; cout << max; return 0; } else if (n > a) max = a; else if (n > b) max = b; else if (a + b > n) max =...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; vector<int> c(n), d(n); for (int i = 1; i < n; i++) { c[i] = a / i; d[i] = b / i; } int x = -1; for (int i = 1; i < n; i++) { int ans = min(c[i], d[n - i]); if (x < ans) x = ans; } cout << x << ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 7; const double eps = 1e-9; const int ALP = 26; int main() { int a, b, n; cin >> n >> a >> b; for (int i = (a + b) / n + 1; i > 0; i--) { if (a / i + b / i >= n && a / i > 0 && b / i > 0) { cout << i << endl; return 0; } ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int, int>; int n, a, b; bool ok(int x) { return (a >= x && b >= x) && (a / x + b / x >= n); } void solve() { cin >> n >> a >> b; int lo = 1, hi = 100; while (lo < hi) { int mid = lo + (hi - lo + 1) / 2;...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, x, max = 0; cin >> n >> a >> b; if (n == a + b) cout << 1; else { for (int i = 1; i < n; i++) { if (max < min(a / (n - i), b / (i))) max = min(a / (n - i), b / (i)); } cout << max; } }
#include <bits/stdc++.h> using namespace std; int N, A, B; bool check(int n) { return (A >= n && B >= n && N <= (A / n + B / n)); } int bsearch(int l, int r) { if (l > r) { return 0; } int mid = (l + r) / 2, ret; if (check(mid)) { ret = bsearch(mid + 1, r); return (mid > ret ? mid : ret); } else {...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, st = 1, dr = 100; cin >> n >> a >> b; int ans = -1; dr = min(a, b); while (st <= dr) { int mij = (st + dr) / 2; if (a / mij + b / mij >= n) { ans = mij; st = mij + 1; } else dr = mij - 1; } cout << ans; }...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e18; const int INF = 0x3f3f3f3f; inline int read() { int f = 1, x = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getch...
#include <bits/stdc++.h> using namespace std; int n, a, b, otv; int main() { cin >> n >> a >> b; for (int i = 1; i < n; i++) { otv = max(min(int(floor(double(a) / i)), int(floor(double(b) / (n - i)))), otv); } cout << otv; }
#include <bits/stdc++.h> using namespace std; int n, a, b; inline bool check(int x) { if (a < x || b < x) { return 0; } return (int)(a / x) + (int)(b / x) >= n; } int main() { scanf("%d%d%d", &n, &a, &b); for (int i = (a + b) / n; i > 0; i--) { if (check(i)) { printf("%d\n", i); break; ...
#include <bits/stdc++.h> using namespace std; bool validmin(int mid, int n, int a, int b) { int platea = a / mid; int plateb = b / mid; if (platea + plateb >= n) return true; else return false; } int mincake(int n, int a, int b) { int lo = 1, hi = a > b ? b : a, mid, ans; while (lo <= hi) { mid ...
#include <bits/stdc++.h> using namespace std; bool f(int m, int a, int b, int n) { int c = 0; if (a < m or b < m) return 0; while (a >= m) { c++; a = a - m; } while (b >= m) { c++; b = b - m; } return c >= n; } int main() { int n, a, b; cin >> n >> a >> b; int l = 1; int h = a + b;...
#include <bits/stdc++.h> using namespace std; template <class t, class u> void chmax(t& a, u b) { if (a < b) a = b; } template <class t, class u> void chmin(t& a, u b) { if (b < a) a = b; } int main() { int n, a, b; scanf("%d", &n); scanf("%d", &a); scanf("%d", &b); int MAX = 0; for (int prefix = 1; pre...
#include <bits/stdc++.h> using namespace std; int n, a, b; void Enter() { cin >> n >> a >> b; } void Solve() { int kq = 0; for (int i = 1; i < n; i++) { kq = max(kq, min(a / i, b / (n - i))); } cout << kq; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); Enter(); Solve(); }
#include <bits/stdc++.h> const int N = 1e6 + 3; const long long INF = 1e18 + 100; const int inf = 1e9 + 100; const int MOD = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; int a, b; cin >> a >> b; int maxi = 0; for (int x = 1; x < n; x++) { maxi = max(min(a /...
#include <bits/stdc++.h> using namespace std; const long long M = 1000000007; const double pi = 3.141592653589793238463; long long modExp(long long x, long long n, long long M) { long long result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % M; x = (x * x) % M; n = n / 2; } return res...
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; } void swap(char a, cha...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; int main() { int n, a, b; scanf("%d%d%d", &n, &a, &b); for (int x = a + b; x > 0; x--) { if (a / x + b / x >= n && a / x != 0 && b / x != 0) { printf("%d", x); return 0; } } printf("%d", 0); return ...
#include <bits/stdc++.h> using namespace std; ifstream in("input.txt"); ofstream out("output.txt"); const int MAXN = 1e9 + 7; const long long MAXL = 1e18; const int N = 1e7; const long double eps = 1e-11; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, a, b; cin >> n >> a >> b; int mini = 0; f...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; int mini = 100000, ans = -1; for (int i = n - 1; i > 0; i--) { int q = b / i; int t = a / (n - i); if (q == 0 || t == 0) { continue; } mini = min(t, q); ans = max(ans, mini); } cout << a...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, maxi = 0; cin >> n >> a >> b; for (int i = 1; i < n; i++) if (min(a / i, b / (n - i)) > maxi) maxi = min(a / i, b / (n - i)); cout << maxi; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n, ans = 0, minAns = 0; cin >> n >> a >> b; for (int i = 1; i < n; i++) { minAns = min(a / i, b / (n - i)); ans = max(ans, minAns); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, a, b, mn, l, mx, mn1 = 1e10, h, t; int main() { cin >> n >> a >> b; mn = min(a, b); mx = max(a, b); long long i = 1; while (i < n && mn / i > 0 && mx / i > 0) { l = min(mn / i, mx / (n - i)); h = max(h, l); i++; } cout << h; return 0...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long n, a, b, i, p, nc; cin >> n >> a >> b; for (p = (a + b) / n; p; --p) { nc = n; if (b < p || a < p) continue; nc -= min(nc - 1, a / p); nc -= min(nc, b / p); if (nc > 0) continue; cout << p <...
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b; cin >> n >> a >> b; long long l = 0, r = a + b; while (r - l > 1) { long long m = (r + l) / 2; if (b / m + a / m >= n && b >= m && a >= m) l = m; else r = m; } cout << l; return 0; }
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007; const long long BIG = 1446803456761533460; const int Big = 336860180; stringstream sss; const long long int maxn = 100010; void MAIN() { long long int n, a, b; cin >> n >> a >> b; long long int s = 0; for (long long int i = (1);...
#include <bits/stdc++.h> using namespace std; template <class T> T pmax(T a, T b) { return max(a, b); } const long long int mod = 1e9 + 7; const long long int Maa = 1e3 + 7; vector<long long int> edge[Maa]; long long int n, m, ans, a, b, c; int main() { long long int l, r; cin >> n >> a >> b; if (a > b) swap(b,...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); ; int n; cin >> n; int a, b; cin >> a >> b; int mi = 0; for (int i = 1; i < n; i++) { mi = max(mi, min(a / i, b / (n - i))); } cout << mi; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, ans = 0; cin >> n >> a >> b; for (int i = 1; i <= n - 1; i++) { ans = max(min(a / i, b / (n - i)), ans); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; int n, a, b; int main() { scanf("%d%d%d", &n, &a, &b); int i; for (i = 1; i <= min(a, b); i++) { if (a / i + b / i < n) break; } printf("%d\n", max(i - 1, 1)); }
#include <bits/stdc++.h> using namespace std; int n, a, b, mx = -1; int main() { scanf("%d %d %d", &n, &a, &b); for (int i = 1; i < n; i++) mx = max(mx, min(a / i, b / (n - i))); printf("%d", mx); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigMod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T modInverse(T a, T M) { return bigmod(a, M - 2, M); } const int d...
#include <bits/stdc++.h> using namespace std; ifstream in("test.in"); ofstream out("test.out"); int n, a, b; bool ok(int x) { if (a / x + b / x >= n && x <= a && x <= b) return true; return false; } int cautbin() { int pas = 1 << 7, r = 0; while (pas) { if (ok(r + pas)) r += pas; pas /= 2; } return ...
#include <bits/stdc++.h> using namespace std; const long long N = 500005; const long long mod = 1e9 + 7; void solve() { long long x = 0, y = 0, c = 0, ans = 0; long long n, m, k, a, b; cin >> n >> a >> b; for (long long i = 1; i < n; ++i) { if (i > a or n - i > b) continue; ans = max(ans, min((a) / i, (...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:36777216") using namespace std; inline double MAX(double a, double b) { return (a > b) ? (a) : (b); } inline int MIN(int a, int b) { return (a < b) ? (a) : (b); } int const sz = 1e5; int main() { long long n, a, b, i, max = 0; cin >> n >> a >> b; for (i = 1...
#include <bits/stdc++.h> using namespace std; int n, a, b; int chk(int p) { int x, y, z; x = a / p; y = n - x; if (y * p <= b) return 1; else return 0; } int main() { int m, i, j, p, q, sz, mx, cnt[1002], k, st, ed, md; while (cin >> n >> a >> b) { st = 1; ed = min(a, b); while (st <= ...
#include <bits/stdc++.h> using namespace std; int main() { double n, a, b, d; cin >> n >> a >> b; int mini = min(a, b); int maxi = max(a, b); for (int i = mini; i >= 1; i--) { int c = mini / i; if ((maxi / i) >= (n - c)) { cout << i; break; } else { continue; } } }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, minn = 0; cin >> n >> a >> b; for (int i = 1; i < n; i++) { if (a / i >= 1 && b / (n - i) >= 1) { if (min(a / i, b / (n - i)) > minn) minn = min(a / i, b / (n - i)); } } printf("%d", minn); return 0; }