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');
ch = getchar();
if (ch < '0' || ch > '9') break;
}
return (ng ? -n : n);
}
template <typename T>
inline T POW(T B, T P) {
if (P == 0) return 1;
if (P & 1)
return B * POW(B, P - 1);
else
return (POW(B, P / 2) * POW(B, P / 2));
}
template <typename T>
inline T Gcd(T a, T b) {
if (a < 0) return Gcd(-a, b);
if (b < 0) return Gcd(a, -b);
return (b == 0) ? a : Gcd(b, a % b);
}
template <typename T>
inline T Lcm(T a, T b) {
if (a < 0) return Lcm(-a, b);
if (b < 0) return Lcm(a, -b);
return a * (b / Gcd(a, b));
}
long long Bigmod(long long base, long long power, long long MOD) {
long long ret = 1;
while (power) {
if (power & 1) ret = (ret * base) % MOD;
base = (base * base) % MOD;
power >>= 1;
}
return ret;
}
bool isVowel(char ch) {
ch = toupper(ch);
if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
return true;
return false;
}
template <typename T>
long long int isLeft(T a, T b, T c) {
return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);
}
long long ModInverse(long long number, long long MOD) {
return Bigmod(number, MOD - 2, MOD);
}
bool isConst(char ch) {
if (isalpha(ch) && !isVowel(ch)) return true;
return false;
}
int toInt(string s) {
int sm;
stringstream second(s);
second >> sm;
return sm;
}
int lol(vector<int> v) {
for (int i = 0; i < v.size(); i++) {
if (i == v[i]) return 0;
}
return 1;
}
long long int DA(int n) {
if (n == 0) return 1;
vector<int> v;
for (int i = 0; i < n; i++) v.push_back(i);
int ans = 0;
do {
ans += lol(v);
} while (next_permutation(v.begin(), v.end()));
return ans;
}
long long int ncr(long long int n, long long int r) {
long long int ans = 1;
r = min(r, n - r);
for (int i = 0; i < r; i++) ans = ans * (n - i);
for (int i = 1; i < r + 1; i++) {
ans /= i;
}
return ans;
}
int main() {
int n, k;
cin >> n >> k;
long long int ans = 0;
for (int i = 0; i <= k; i++) {
ans += ncr(n, n - i) * DA(i);
}
cout << ans << endl;
return 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(s);
}
unsigned long long fac(int k) {
unsigned long long ans = 1;
for (int i = 2; i <= k; i++) {
ans *= i;
}
return ans;
}
unsigned long long nCk(int n, int k) {
unsigned long long res = 1;
if (k > n - k) {
k = n - k;
}
for (int i = 0; i < k; i++) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
unsigned long long ans = 1;
unsigned long long sum_0 = 1;
unsigned long long sum_1 = 0;
for (int i = 2; i <= k; i++) {
unsigned long long t = (i - 1) * (sum_0 + sum_1);
sum_0 = sum_1;
sum_1 = t;
ans += t * nCk(n, i);
}
cout << ans << endl;
return 0;
}
|
#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 += 1;
cout << s;
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#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][j];
}
}
d[0] = 1;
for (int i = 2; i <= k; i++) {
d[i] = (i - 1) * (d[i - 1] + d[i - 2]);
}
long long ans = 0;
for (int i = 0; i <= k; i++) {
ans += (dp[n][i]) * d[i];
}
cout << ans;
return 0;
}
|
#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 %= mod;
while (b) {
if (b & 1) {
res = (res + a) % mod;
}
a = (2 * a) % mod;
b >>= 1;
}
return res;
}
long long power(long long x, long long y, long long mod2) {
long long res = 1;
x %= mod2;
while (y) {
if (y & 1) res = fastMul(res, x, mod2);
y >>= 1;
x = fastMul(x, x, mod2);
}
return res;
}
long long inv(long long x, long long mod) { return power(x, mod - 2, mod); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
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 += 2LL * (n * (n - 1) * (n - 2)) / 6;
if (k >= 4) ans += 9LL * (n * (n - 1) * (n - 2) * (n - 3) / 24);
cout << ans << "\n";
return 0;
}
|
#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;
}
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int ans = 0;
cin >> n >> k;
for (long long int i = 0; i <= k; i++) {
long long int p = ncr(n, i);
ans += p * dr[i];
}
cout << ans;
return 0;
}
|
#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) / 24) * 9;
long long ans = 0;
for (long long i = 0; i <= k; i++) ans += a[i];
cout << ans << '\n';
return 0;
}
|
#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;
ans += 1LL * n * (n - 1) / 2LL * (n - 2) * (n - 3) / 2LL;
}
if (k >= 3) {
ans += 1LL * n * (n - 1) * (n - 2) / 3LL;
}
if (k >= 2) {
ans += 1LL * n * (n - 1) / 2LL;
}
if (k >= 1) {
ans += 1;
}
printf("%lld\n", ans);
return 0;
}
|
#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 res = up / down;
return res;
}
int main() {
ios_base::sync_with_stdio(false);
long long n, k;
cin >> n >> k;
long long a[5];
a[2] = 1, a[3] = 2, a[4] = 9;
long long ans = 1;
for (long long take = 2; take <= k; take++) {
long long res = ncr(n, take);
res = (res * a[take]);
ans += res;
}
cout << ans << "\n";
return 0;
}
|
#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 - 1) * (n - 2) * (n - 3) / 1 / 2 / 3 / 4 * cnt4;
cout << ans;
}
|
#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(false);
cin.tie(0);
long long arr[5] = {0, 0, 1, 2, 9};
long long n, k, i, ans = 0;
cin >> n >> k;
for (i = n - k; i < n; i++) {
ans += (nCr(n, n - i) * arr[n - i]);
}
cout << ans + 1 << '\n';
return 0;
}
|
#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;
}
if (k >= 4) {
long long tmp = n;
int t = 4, r = n - 1;
while (r >= n - 3) {
tmp *= r;
while (tmp % t == 0 && t > 1) {
tmp /= t;
--t;
}
--r;
}
ans += 9 * tmp;
}
cout << ans << endl;
}
return 0;
}
|
#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) {
ans = 1;
ans += (n * (n - 1)) / 2;
ans += (n * ((n - 1) * (n - 2))) / 6 * dear[3];
}
if (k == 4) {
ans = 1;
ans += (n * (n - 1)) / 2;
ans += (n * ((n - 1) * (n - 2))) / 6 * dear[3];
ans += (n * ((n - 1) * ((n - 2) * (n - 3)))) / 24 * dear[4];
}
cout << ans << endl;
}
|
#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);
}
if (i == 3) {
ans += 2 * c(n, 3);
}
if (i == 4) {
ans += 9 * c(n, 4);
}
}
printf("%lld\n", ans);
return 0;
}
|
#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) * (n - 3)) / 4;
}
return res;
}
long long D(int k) {
if (k == 2) return 1;
if (k == 3) return 2;
if (k == 4) return 9;
}
int main() {
long long n, k;
cin >> n >> k;
long long ans = 1;
while (k > 1) {
long long kk = (C(n, k)) * (D(k));
ans += kk;
k--;
}
cout << ans;
}
|
#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] = 1;
a[3] = 2;
a[4] = 9;
long long int n, k;
cin >> n >> k;
b[0] = 1;
b[2] = (n * (n - 1)) / 2;
b[3] = (b[2] * (n - 2)) / 3;
b[4] = (b[3] * (n - 3)) / 4;
for (i = 0; i <= k; i++) ans += (b[i] * a[i]);
cout << ans << "\n";
}
|
#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 * 9 +
n * (n - 1) * (n - 2) / 6 * 2 + n * (n - 1) / 2 + 1;
return 0;
}
|
#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 = 1, ans2 = 1;
for (int i = d, j = l; (i > k || j > 0); i--, j--) {
if (i > k) {
ans1 *= i;
}
if (j > 0) {
ans2 *= j;
}
}
return ((ans1 / ans2));
}
int main() {
int n, k;
cin >> n >> k;
int d[4] = {0, 1, 2, 9};
unsigned long long result = 1;
for (; k > 1; k--) {
result += combi(n, k) * d[k - 1];
}
cout << result << "\n";
}
|
#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)) * 2;
else if (k == 4)
return ((n * (n - 1) * (n - 2) * (n - 3)) / (1 * 2 * 3 * 4)) * 9;
else
return -1;
}
int main() {
long long i, n, k, ans = 0;
scanf("%lld", &n);
scanf("%lld", &k);
for (i = k; i >= 0; i--) {
ans += ans_k(i, n);
}
printf("%lld\n", ans);
return 0;
}
|
#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() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#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;
} else {
comb[n][k] = assign(n - 1, k) + assign(n - 1, k - 1);
}
}
return comb[n][k];
}
return 0;
}
}
int main() {
int n, k;
cin >> n >> k;
long long int ans = 0;
for (int i = 0; i < 1002; i++) {
if (i == 0) {
derang[0] = 1;
} else if (i == 1) {
derang[1] = 0;
} else {
derang[i] = (i - 1) * (derang[i - 1] + derang[i - 2]);
}
}
for (int i = 0; i < 1002; i++) {
comb[i].resize(i + 1, -1);
}
for (int i = n - k; i <= n; i++) {
ans += (assign(n, i) * derang[n - i]);
}
cout << ans << endl;
}
|
#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 - 2));
}
void fact(long long int n) {
factorial[0] = 1;
for (int i = 1; i <= n; i++) factorial[i] = factorial[i - 1] * i;
}
long long int nCr(long long int n, long long int r) {
long long int res = 1;
for (int i = 0; i < r; i++) {
res *= (n - i);
}
return res / factorial[r];
}
int main() {
int n, k;
cin >> n >> k;
long long int ans = 0;
fact(5);
memset(derange, -1, sizeof(derange));
for (int i = 0; i <= k; i++) {
ans += nCr(n, i) * derangements(i);
}
cout << ans << "\n";
return 0;
}
|
#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 >= 2; i--) {
a += per(n, i) * m[i];
}
cout << a;
return 0;
}
|
#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 U>
struct par {
T x;
U y;
par() : x(-1), y(-1) {}
par(const T& x, const U& y) : x(x), y(y) {}
bool operator<(const par& other) const {
if (x == other.x) return y < other.y;
return x < other.x;
}
bool operator==(const par& other) const {
return x == other.x && y == other.y;
}
par operator-(const par& b) const { return {x - b.x, y - b.y}; }
};
template <class T>
inline vector<T> rv(long long n) {
vector<T> v(n);
for (long long i = 0; i < (n); i++) cin >> v[i];
return v;
}
template <class T>
inline void pv(const vector<T>& v) {
for (long long i = 0; i < (v.size()); i++) cout << v[i] << " ";
cout << endl;
}
template <class T, class U>
inline void amax(T& a, const U& b) {
if (a < b) a = b;
}
template <class T, class U>
inline void amin(T& a, const U& b) {
if (a > b) a = b;
}
template <class T, class U>
inline T min(T& a, const U& b) {
return a > b ? b : a;
}
template <class T, class U>
inline T max(T& a, const U& b) {
return a < b ? b : a;
}
const long long MOD = 1e9 + 7;
const long long MOD1 = 998244353;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
long long GCD(long long a, long long b) {
if (a < b) swap(a, b);
while (b) {
long long r = a % b;
a = b;
b = r;
}
return a;
}
int main(int argc, char** argv) {
long long n, k, ans = 1;
cin >> n >> k;
if (k == 4) {
ans += (n) * (n - 1) * (n - 2) * (n - 3) * 9 / 24;
k--;
}
if (k == 3) {
ans += (n) * (n - 1) * (n - 2) * 2 / 6;
k--;
}
if (k == 2) {
ans += (n) * (n - 1) / 2;
k--;
}
cout << ans;
return 0;
}
|
#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) {
ans += n * (n - 1) / 2;
}
ans += 1;
cout << ans << endl;
}
|
#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 < 1001; ++i)
all[3][i] = all[3][i - 1] + (i - 1LL) * (i - 1LL);
all[4][4] = 24;
for (long long i = 5; i < 1001; ++i) {
all[4][i] =
all[4][i - 1] + (i - 1LL) * (i - 1LL) * (i - 1LL) + (i - 1LL) * d;
d += a;
a++;
}
cout << all[k][n];
return 0;
}
|
#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(long long a, long long n) {
long long r = 1 % P;
for (a %= P; n; a = a * a % P, n >>= 1)
if (n & 1) r = r * a % P;
return r;
}
const int maxn = 1e5 + 5;
const int maxm = 1e6 + 5;
int n;
long long fac[2010], inv[2010];
long long comb(int x, int y) {
long long ans = 1;
for (int i = 1; i <= y; i++) {
ans *= x;
ans /= i;
x--;
}
return ans;
}
int g[5] = {0, 0, 1, 2, 9};
signed main() {
fac[0] = inv[0] = 1;
for (int i = 1; i <= 2000; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = qpow(fac[i], P - 2);
}
int n, k;
cin >> n >> k;
long long ans = 0;
for (int i = 1; i <= k; i++) ans += comb(n, i) * g[i];
ans++;
cout << ans;
}
|
#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;
}
if (i == 3) {
ans += n * (n - 1) * (n - 2) / 6 * 2;
}
if (i == 4) {
ans += n * (n - 1) * (n - 2) * (n - 3) / 24 * 9;
}
}
printf("%I64d\n", ans);
}
}
int abs(int num) {
if (num > 0) return num;
return -num;
}
|
#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 >= mod) x -= mod;
assert(x >= 0 && x < mod);
}
void et() {
puts("-1");
exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
long long ans = 1;
while (y > 0) {
if (y & 1) ans = (x * ans) % mod;
x = x * x % mod;
y >>= 1;
}
return ans;
}
long long gcd1(long long x, long long y) {
long long z = y;
while (x % y != 0) {
z = x % y;
x = y;
y = z;
}
return z;
}
long long ans[7];
void fmain(int ID) {
scanf("%d%d", &n, &k);
ans[0] = 1;
ans[2] = n * (n - 1) / 2;
ans[3] = n * (n - 1) * (n - 2) / 3;
long long t = (long long)n * (n - 1) * (n - 2) * (n - 3) / 6 / 4;
ans[4] = t * 9;
for (int(i) = 1; (i) <= (int)(4); (i)++) ans[i] += ans[i - 1];
printf("%lld\n", ans[k]);
}
int main() {
int t = 1;
for (int(i) = 1; (i) <= (int)(t); (i)++) {
fmain(i);
}
return 0;
}
|
#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 (k == 3) {
cout << (n * (n - 1) * (n - 2)) / 3 + (n * (n - 1) / 2) + 1;
} else if (k == 4) {
cout << (n * (n - 1) * (n - 2) * (n - 3) * 3) / 8 +
(n * (n - 1) * (n - 2)) / 3 + (n * (n - 1)) / 2 + 1;
}
cout << endl;
return 0;
}
|
#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 = (res << 1) + (res << 3) + ch - 48)
;
flag && (res = -res);
}
template <typename T>
void Out(T x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) Out(x / 10);
putchar(x % 10 + '0');
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long pow_mod(long long x, long long n, long long mod) {
long long res = 1;
while (n) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
long long fact_pow(long long n, long long p) {
long long res = 0;
while (n) {
n /= p;
res += n;
}
return res;
}
long long mult(long long a, long long b, long long p) {
a %= p;
b %= p;
long long r = 0, v = a;
while (b) {
if (b & 1) {
r += v;
if (r > p) r -= p;
}
v <<= 1;
if (v > p) v -= p;
b >>= 1;
}
return r;
}
long long quick_pow(long long a, long long b, long long p) {
long long r = 1, v = a % p;
while (b) {
if (b & 1) r = mult(r, v, p);
v = mult(v, v, p);
b >>= 1;
}
return r;
}
bool CH(long long a, long long n, long long x, long long t) {
long long r = quick_pow(a, x, n);
long long z = r;
for (long long i = 1; i <= t; i++) {
r = mult(r, r, n);
if (r == 1 && z != 1 && z != n - 1) return true;
z = r;
}
return r != 1;
}
bool Miller_Rabin(long long n) {
if (n < 2) return false;
if (n == 2) return true;
if (!(n & 1)) return false;
long long x = n - 1, t = 0;
while (!(x & 1)) {
x >>= 1;
t++;
}
srand(time(NULL));
long long o = 8;
for (long long i = 0; i < o; i++) {
long long a = rand() % (n - 1) + 1;
if (CH(a, n, x, t)) return false;
}
return true;
}
void exgcd(long long a, long long b, long long &x, long long &y) {
if (!b) {
x = 1, y = 0;
return;
}
exgcd(b, a % b, x, y);
long long t = x;
x = y, y = t - (a / b) * y;
}
long long inv(long long a, long long b) {
long long x, y;
return exgcd(a, b, x, y), (x % b + b) % b;
}
long long crt(long long x, long long p, long long mod) {
return inv(p / mod, mod) * (p / mod) * x;
}
long long fac(long long x, long long a, long long b) {
if (!x) return 1;
long long ans = 1;
for (long long i = 1; i <= b; i++)
if (i % a) ans *= i, ans %= b;
ans = pow_mod(ans, x / b, b);
for (long long i = 1; i <= x % b; i++)
if (i % a) ans *= i, ans %= b;
return ans * fac(x / a, a, b) % b;
}
long long C(long long n, long long m, long long a, long long b) {
long long N = fac(n, a, b), M = fac(m, a, b), Z = fac(n - m, a, b), sum = 0,
i;
for (i = n; i; i = i / a) sum += i / a;
for (i = m; i; i = i / a) sum -= i / a;
for (i = n - m; i; i = i / a) sum -= i / a;
return N * pow_mod(a, sum, b) % b * inv(M, b) % b * inv(Z, b) % b;
}
long long exlucas(long long n, long long m, long long p) {
long long t = p, ans = 0, i;
for (i = 2; i * i <= p; i++) {
long long k = 1;
while (t % i == 0) {
k *= i, t /= i;
}
ans += crt(C(n, m, i, k), p, k), ans %= p;
}
if (t > 1) ans += crt(C(n, m, t, t), p, t), ans %= p;
return ans % p;
}
const long long N = 2e5 + 10;
long long C(long long n, long long m) {
if (m == 1) return n;
if (m == 2) return n * (n - 1) / 2;
if (m == 3) return n * (n - 1) * (n - 2) / 6;
if (m == 4) return n * (n - 1) * (n - 2) * (n - 3) / 24;
}
signed main() {
std::ios::sync_with_stdio(false);
long long n, k;
cin >> n >> k;
if (k == 1)
cout << 1 << '\n';
else if (k == 2)
cout << C(n, 2) + 1 << '\n';
else if (k == 3)
cout << 2 * C(n, 3) + C(n, 2) + 1 << '\n';
else
cout << 9 * C(n, 4) + 2 * C(n, 3) + C(n, 2) + 1 << '\n';
return 0;
}
|
#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 long int dp[n + 1][n + 1];
dp[0][0] = 1;
dp[1][0] = 1;
dp[1][1] = 1;
for (int i = 2; i <= n; i++) {
dp[i][0] = 1;
for (int j = 1; j < i; j++) {
dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
}
dp[i][i] = 1;
}
return dp[n][k];
}
int main() {
int n, k;
cin >> n >> k;
long long int ans = 1, f[] = {0, 0, 1, 2, 9};
for (int i = 1; i <= k; i++) {
ans = ans + nck2(n, i) * f[i];
}
cout << ans << endl;
return 0;
}
|
#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 temp;
if (k == 1) {
temp = 1;
} else if (k == 2) {
temp = 1 + C(n, 2);
} else if (k == 3) {
temp = 1 + C(n, 2) + C(n, 3) * 2;
} else if (k == 4) {
temp = 1 + C(n, 2) + C(n, 3) * 2 + C(n, 4) * 9;
}
printf("%lld\n", temp);
return 0;
}
|
#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;
scanf("%d %d", &n, &k);
long long int ans = 0;
for (int i = 0; i <= k; i++) ans += (nCr(n, i) * d[i]);
printf("%lld", ans);
return 0;
}
|
#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 = 1;
int main() {
read(n), read(m);
if (m > 1) ans += (n - 1) * n / 2;
if (m > 2) ans += 2 * (n - 2) * (n - 1) * n / 6;
if (m > 3) ans += 9 * (n - 3) * (n - 2) * (n - 1) * n / 24;
printf("%lld", ans);
return 0;
}
|
#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;
for (int i = 1; i <= k; i++) {
ret *= n - i + 1;
ret /= i;
}
return ret;
}
|
#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 = tmp / 6;
} else {
tmp = n * (n - 1) * (n - 2) * (n - 3);
tmp = tmp / 24;
}
return tmp;
}
void solve() {
cin >> n >> k;
long long ans = 0;
for (int i = 0; i < k + 1; i++) {
ans += nck(i) * d[i];
}
cout << ans << '\n';
}
int main() {
solve();
return 0;
}
|
#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>::const_iterator itr = cont.begin();
typename map<T, T1>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) out << *itr << " ";
out << endl;
return out;
}
template <typename T>
ostream &operator<<(ostream &out, set<T> cont) {
typename set<T>::const_iterator itr = cont.begin();
typename set<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) out << *itr << " ";
out << endl;
return out;
}
template <typename T>
ostream &operator<<(ostream &out, multiset<T> cont) {
typename multiset<T>::const_iterator itr = cont.begin();
typename multiset<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) out << *itr << " ";
out << endl;
return out;
}
template <typename T,
template <typename ELEM, typename ALLOC = allocator<ELEM>> class CONT>
ostream &operator<<(ostream &out, CONT<T> cont) {
typename CONT<T>::const_iterator itr = cont.begin();
typename CONT<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) out << *itr << " ";
out << endl;
return out;
}
template <typename T, unsigned int N, typename CTy, typename CTr>
typename enable_if<!is_same<T, char>::value, basic_ostream<CTy, CTr> &>::type
operator<<(basic_ostream<CTy, CTr> &out, const T (&arr)[N]) {
for (auto i = 0; i < N; ++i) out << arr[i] << " ";
out << endl;
return out;
}
template <typename T>
T gcd(T a, T b) {
T min_v = min(a, b);
T max_v = max(a, b);
while (min_v) {
T temp = max_v % min_v;
max_v = min_v;
min_v = temp;
}
return max_v;
}
template <typename T>
T lcm(T a, T b) {
return (a * b) / gcd(a, b);
}
template <typename T>
T fast_exp_pow(T base, T exp, T mod) {
T res = 1;
while (exp) {
if (exp & 1) {
res *= base;
res %= mod;
}
exp >>= 1;
base *= base;
base %= mod;
}
return res % mod;
}
int N, K;
int noMatch[10];
long long answer = 1;
long long coeff(int val1, int val2) {
long long ret = 1;
val2 = min(val2, N - val2);
for (auto i = 1; i <= val2; ++i) {
ret *= val1;
--val1;
}
for (auto i = 1; i <= val2; ++i) {
ret /= i;
}
return ret;
}
int main() {
scanf("%d%d", &N, &K);
for (auto i = 1; i <= K; ++i) {
vector<int> perm;
for (auto j = 1; j <= i; ++j) {
perm.push_back(j);
}
do {
int diff = 0;
for (auto j = 0; j < perm.size(); ++j) {
if (j + 1 != perm[j]) {
++diff;
}
}
if (diff == perm.size()) {
++noMatch[i];
}
} while (next_permutation(perm.begin(), perm.end()));
}
for (auto i = N - K; i <= N; ++i) {
answer += coeff(N, i) * noMatch[N - i];
}
printf("%lld\n", answer);
return 0;
}
|
#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("1");
if (k == 2) printf("%lld", n * (n - 1) / 2 + 1);
if (k == 3) printf("%lld", n * (n - 1) * (n - 2) / 3 + n * (n - 1) / 2 + 1);
if (k == 4)
printf("%lld", n * (n - 1) * (n - 2) * (n - 3) / 8 * 3 +
n * (n - 1) * (n - 2) / 3 + n * (n - 1) / 2 + 1);
return 0;
}
|
#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 += ((n * (n - 1) * (n - 2) * (n - 3)) / 24) * 9;
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long int t;
t = 1;
while (t--) {
solve();
}
return 0;
}
|
#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 = stold(t);
}
template <class H, class... T>
void read(H& h, T&... t) {
read(h);
read(t...);
}
template <class A>
void read(vector<A>& x) {
for (auto& a : x) read(a);
}
template <class A, size_t S>
void read(array<A, S>& x) {
for (auto& a : x) read(a);
}
const int mod = 1e9 + 7;
long long int primeLimit = 1e5;
const double PI = acos(-1);
bool prime[100000];
string LongestPalindromicPrefix(string str) {
string temp = str + '?';
reverse(str.begin(), str.end());
temp += str;
long long int n = temp.length();
long long int lps[n];
fill(lps, lps + n, 0);
for (long long int i = 1; i < n; i++) {
long long int len = lps[i - 1];
while (len > 0 && temp[len] != temp[i]) {
len = lps[len - 1];
}
if (temp[i] == temp[len]) {
len++;
}
lps[i] = len;
}
return temp.substr(0, lps[n - 1]);
}
bool binarySearchFloat(float lower, float higher, float maxErrorAllowed,
long long int numberOfTimesWanttoRunCode) {
float l = lower, r = higher;
float eps = maxErrorAllowed;
long long int iteration_count = numberOfTimesWanttoRunCode;
for (long long int i = 0; i < iteration_count && l + eps < r; ++i) {
}
}
void primefinder() {
memset(prime, true, sizeof(prime));
prime[1] = false;
prime[0] = false;
for (long long int i = 2; i < primeLimit; i++) {
if (prime[i]) {
for (long long int j = i * i; j < primeLimit; j += i) {
prime[j] = false;
}
}
}
}
long long fast_pow(long long int x, long long int y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
long long Fast_pow(long long int x, long long int y, long long int p) {
long long res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long int nCr(long long int n, long long int r) {
long long int res = 1;
if (n - r < r) r = n - r;
for (long long int i = 0; i < r; i++) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, k;
cin >> n >> k;
long long int ans = 1;
if (k > 1) ans += nCr(n, 2);
if (k > 2) ans += nCr(n, 3) * 2;
if (k > 3) ans += nCr(n, 4) * 9;
cout << ans;
}
|
#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 arr[i];
for (int j = 0; j < i; j++) {
arr[j] = j;
}
int cnt = 0;
do {
bool b = 1;
for (int j = 0; j < i; j++) {
if (arr[j] == j) b = 0;
}
if (b) cnt++;
} while (next_permutation(arr, arr + i));
ans += cnt * com(n, i);
}
cout << ans;
return 0;
}
|
#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 *= 9;
}
return num;
}
int main() {
unsigned long long n, k;
cin >> n >> k;
unsigned long long count = 0;
for (int i = 0; i <= k; i++) {
if (i == 0)
count++;
else if (i == 1)
continue;
else {
count += val(n, i);
}
}
cout << count;
return 0;
}
|
#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 - i)));
}
cout << val;
return 0;
}
|
#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;
return GCD(b, a % b);
}
long long int exp(long long int a, long long int n) {
if (n == 0) return 1;
if (n == 1) return check(a);
long long int b = exp(a, n / 2);
if (n % 2 == 0) return check(b * b);
return check(b * check(b * a));
}
const int N = 200010;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cons = 1e9 + 7;
int n, a, b;
cin >> n >> a >> b;
int ans = 0;
while (true) {
ans++;
int c1 = a / ans;
int c2 = b / ans;
if (c1 > 0 && c2 > 0 && (c1 + c2 >= n))
continue;
else
break;
}
cout << ans - 1;
}
|
#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);
cout.tie(0);
}
int32_t main() {
c_p_c();
long long n, a, b;
cin >> n >> a >> b;
long long i = 100;
while (i >= 1) {
long long pa = a / i;
long long push_back = b / i;
if (pa > 0 && push_back > 0 && pa + push_back >= n) break;
i--;
}
cout << i;
return 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, typename T1, typename T2>
void read(T &x, T0 &y, T1 &z, T2 &w) {
cin >> x >> y >> z >> w;
}
template <typename T, typename T0>
void read(pair<T, T0> &p) {
cin >> p.fst >> p.scd;
}
template <typename T>
void read(vector<T> &oneD, long long int n) {
for (long long int(i) = 0; (i) < (n); ++(i)) {
long long int x;
read(x);
oneD.push_back(x);
}
}
template <typename T>
void read(T oneD[], long long int n) {
for (long long int i = 0; i < n; i++) {
read(oneD[i]);
}
}
template <typename T>
void write(T &x) {
cout << x << " ";
}
template <typename T, typename T0>
void write(T &x, T0 &y) {
cout << x << " " << y << "\n";
}
template <typename T, typename T0, typename T1>
void write(T &x, T0 &y, T1 &z) {
cout << x << " " << y << " " << z << "\n";
}
template <typename T, typename T0, typename T1, typename T2>
void write(T &x, T0 &y, T1 &z, T2 &w) {
cout << x << " " << y << " " << z << " " << w << "\n";
}
template <typename T, typename T0>
void write(pair<T, T0> &p) {
write(p.fst);
write(p.scd);
cout << endl;
}
template <typename T>
void write(vector<T> &oneD) {
for (long long int i = 0; i < oneD.size(); i++) {
write(oneD[i]);
}
cout << endl;
}
template <typename T>
void write(T oneD[], int n) {
for (long long int i = 0; i < n; i++) {
write(oneD[i]);
}
cout << endl;
}
template <typename T, typename T0>
void write(map<T, T0> &mpp) {
for (auto it : mpp) {
write(it.fst);
cout << ": ";
write(it.scd);
cout << "\n";
}
cout << endl;
}
vector<long long int> seive;
void Seive() {
const long long int maxn = 1000005;
seive.resize(maxn);
for (long long int(i) = 0; (i) < (maxn); ++(i)) seive[i] = i;
seive[1] = -1;
seive[0] = -1;
for (long long int(i) = 2; (i) <= (maxn); (i) += (1))
if (i == seive[i])
for (long long int j = 2 * i; j < maxn; j += i)
if (seive[j] == j) seive[j] = i;
}
long long int extended_GCD(long long int a, long long int b, long long int &x,
long long int &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
long long int x1, y1;
long long int gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
long long int modinv(long long int a, long long int mod = 1000000007) {
long long int x, y;
extended_GCD(a, mod, x, y);
if (x < 0) x += mod;
return x;
}
long long int find_x_CRT(long long int num[], long long int rem[],
long long int n) {
long long int pro = 1;
for (long long int(i) = 0; (i) < (n); ++(i)) pro *= num[i];
long long int res = 0;
for (long long int(i) = 0; (i) < (n); ++(i)) {
long long int pp = pro / num[i];
res += (rem[i] * modinv(pp, num[i]) * pp);
}
res %= pro;
return res;
}
long long int power(long long int a, long long int b,
long long int m = 1000000007) {
a %= m;
long long int res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
long long int powe(long long int a, long long int b,
long long int m = 1000000007) {
long long int res = 1;
while (b > 0) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
long long int gcd(long long int a, long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
string getString(char x) {
string s(1, x);
return s;
}
bool func(long long int mid, long long int n, long long int a,
long long int b) {
long long int t = a / mid;
long long int p = b / mid;
if (t >= 1 && p >= 1 && (t + p) >= n)
return true;
else {
return false;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long int n, a, b;
read(n, a, b);
long long int st = 1, en = (a + b), ans = 0;
long long int mid = (st + en) / 2;
while (st <= en) {
mid = (st + en) / 2;
if (func(mid, n, a, b)) {
ans = max(ans, mid);
st = mid + 1;
} else {
en = mid - 1;
}
}
cout << ans;
return 0;
}
|
#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)) {
ans = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
cout << ans << endl;
return 0;
}
|
#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 + (n - 1));
cout << ar[n - 2];
return 0;
}
|
#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 >= t) {
int cntb = b / t;
int cnta = a / t;
if (cnta + cntb >= n)
fb = 1;
else
fb = 0;
}
return fa || fb;
}
int main() {
scanf("%d", &n);
scanf("%d", &a);
scanf("%d", &b);
int ans = 1;
for (int i = 1; i < 210; i++) {
if (ok(i)) ans = i;
}
printf("%d", ans);
}
|
#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(NULL);
bool flag = true, flag1 = true, flag2 = false, flag3 = false;
char var;
string str;
cin >> n >> a >> b;
for (int i = 1; i < n; i++) {
count = a / i;
count1 = b / (n - i);
max1 = max(max1, (min(count, count1)));
}
cout << max1;
}
|
#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 (i = 1; i <= min(x, y); i++) {
tx = x;
ty = y;
tn = n;
while (tn > 0) {
if (tx - i >= 0) {
tx = tx - i;
} else if (ty - i >= 0) {
ty = ty - i;
} else {
break;
}
tn--;
}
if (tn == 0) {
ans = i;
}
}
cout << ans;
return 0;
}
|
#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, 1};
int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};
int main() {
long long n, a, b, ans = 0;
scanf("%lld%lld%lld", &n, &a, &b);
for (int i = 1; i <= n - 1; ++i) {
ans = max(ans, min(a / i, b / (n - i)));
}
printf("%lld\n", ans);
return 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 = floor((a + b) / n);
if (max > a)
max = a;
else if (max > b)
max = b;
for (i = 1; i <= max; i++) {
x = a;
y = b;
z = n;
while (z > 0) {
if (x - i >= 0)
x -= i;
else if (y - i >= 0)
y -= i;
else
break;
z--;
}
if (min >= x + y) min = x + y;
}
if (flag == 0) {
cout << "wtf?";
min = a + b;
for (i = 1; i <= max; i++) {
x = a;
y = b;
z = n;
while (z > 0) {
if (y - i >= 0)
y -= i;
else if (x - i >= 0)
x -= i;
else
break;
z--;
}
if (min >= x + y) min = x + y;
cout << "\n" << x << " " << y << "\n";
}
}
max = (a + b - min) / n;
cout << 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 << endl;
return 0;
}
|
#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;
ok(mid) ? lo = mid : hi = mid - 1;
}
cout << lo << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
while (t--) solve();
}
|
#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 {
return bsearch(l, mid - 1);
}
return 0;
}
int main() {
cin >> N >> A >> B;
cout << bsearch(1, 100) << endl;
return 0;
}
|
#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 = getchar();
}
return x * f;
}
int n, a, b;
int fun(int x) {
if (a / x + b / x >= n && a >= x && b >= x) return 1;
return 0;
}
int main() {
cin >> n >> a >> b;
int l = 1, r = 100;
int ma = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (fun(mid)) {
ma = max(ma, mid);
l = mid + 1;
} else
r = mid - 1;
}
cout << ma << endl;
}
|
#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;
}
}
return 0;
}
|
#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 = lo + (hi - lo) / 2;
if (validmin(mid, n, a, b)) {
lo = mid + 1;
ans = mid;
} else
hi = mid - 1;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, a, b;
cin >> n >> a >> b;
cout << mincake(n, a, b) << endl;
}
|
#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;
int ans = 1;
while (h >= l) {
int m = (l + h) / 2;
if (f(m, a, b, n)) {
ans = max(ans, m);
l = m + 1;
} else
h = m - 1;
}
cout << ans << endl;
return 0;
}
|
#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; prefix < n; ++prefix) {
int sufix = n - prefix;
if (prefix > a || sufix > b) continue;
chmax(MAX, min(a / prefix, b / sufix));
}
return !printf("%d\n", MAX);
}
|
#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 / x, b / (n - x)), maxi);
}
cout << maxi;
}
|
#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 result;
}
bool sortbysec(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return (a.second < b.second);
}
bool vow(char ch) {
return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}
bool isPrime(long long n) {
for (long long i = 2; i * i <= n; i++)
if (n % i == 0) return false;
return true;
}
long long fast_exp(long long x, long long n) {
long long ans = 1;
while (n) {
if (n & 1) {
ans *= x;
ans %= M;
}
n = n >> 1;
x = (x * x) % M;
}
return ans;
}
long long inverse(long long x) { return fast_exp(x, M - 2); }
long long combination(long long n, long long r) {
if (r == 0)
return 1;
else {
long long ans = n % M;
ans *= combination(n - 1, r - 1) % M;
ans %= M;
ans *= inverse(r) % M;
ans %= M;
return ans;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
;
long long n, a, b, q;
cin >> n >> a >> b;
for (long long i = min(a, b); i > 0; i--) {
q = a / i + b / i;
if (q >= n) return cout << i, 0;
}
}
|
#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, char b) {
char t;
t = a;
a = b;
b = t;
}
long long fact(long long n) {
if (n <= 1)
return 1;
else
return n * fact(n - 1);
}
long long comb(long long n, long long k) {
long long res = 1;
if (k > n - k) k = n - k;
for (long long i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
long long GCD(long long a, long long b) {
if (b == 1)
return 1;
else
return GCD(b, a % b);
}
long long digSum(long long n) {
long long c = 0;
while (n > 0) {
long long x = n % 10;
c = c + x;
n = n / 10;
}
return c;
}
vector<vector<long long> > v(100010);
vector<bool> th(100010), ch(100010);
bool DFS(long long n) {
stack<long long> s;
long long ans = 0;
ch[n] = true;
s.push(n);
while (s.size() > 0) {
long long x = s.top();
s.pop();
for (long long i = 0; i < v[x].size(); i++) {
if (ch[v[x][i]] == false) {
s.push(v[x][i]);
ch[v[x][i]] = true;
}
}
}
return true;
}
queue<int> q;
void BFS(long long n) {
long long i, le[n + 1];
q.push(n);
le[n] = 0;
ch[n] = true;
while (q.size() > 0) {
long long x = q.front();
q.pop();
for (i = 0; i < v[x].size(); i++) {
if (ch[v[x][i]] == false) {
q.push(v[x][i]);
ch[v[x][i]] = true;
le[v[x][i]] = le[x] + 1;
}
}
}
}
long long count(long long n) {
long long c = 0, k = n;
while (k > 0) {
long long x = k % 10;
c = c + x;
k = k / 10;
}
return c;
}
double area(long long x1, long long y1, long long x2, long long y2,
long long x3, long long y3) {
return abs((double)((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))) /
(double)(2));
}
bool isBin(long long n) {
while (n > 0) {
long long x = n % 10;
if (x > 1) return false;
n /= 10;
}
return true;
}
long long ans[1001500] = {0};
long long near(long long n) {
long long i = n - 1, j = n + 1, c = 0, d = 0;
while (1) {
if (isPrime(i) == true) return i / 2;
if (isPrime(j) == true) return j / 2;
i--;
j++;
}
}
long long modRecursion(long long a, long long b, long long c) {
if (b == 0) return 1;
if (b == 1)
return a % c;
else if (b % 2 == 0) {
return modRecursion((a * a) % c, b / 2, c);
} else {
return (a * modRecursion((a * a % c), b / 2, c)) % c;
}
}
int d, x, y;
void extendedEuclid(int A, int B) {
if (B == 0) {
d = A;
x = 1;
y = 0;
} else {
extendedEuclid(B, A % B);
int temp = x;
x = y;
y = temp - (A / B) * y;
}
}
int modInverse(int A, int M) {
extendedEuclid(A, M);
return (x % M + M) % M;
}
int main() {
long long n, a, b;
cin >> n >> a >> b;
if (a + b == n) {
cout << 1;
return 0;
}
long long i = 1, j = (a + b) / n, k = min(a, b);
j = min(k, j);
long long mid;
while (i <= j) {
mid = (i + j) / 2;
long long x = a / mid + b / mid;
if (a % mid == 0 && b % mid == 0 && a + b == n) {
cout << mid;
return 0;
} else if (x < n) {
j = mid - 1;
} else {
i = mid + 1;
}
mid = (i + j) / 2;
}
cout << mid;
}
|
#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 0;
}
|
#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;
for (int i = 1; i < n; ++i) {
int fir = a / i;
int sec = b / (n - i);
mini = max(mini, min(fir, sec));
}
cout << mini << "\n";
return 0;
}
|
#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 << ans;
}
|
#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 << endl;
return 0;
}
return 0;
}
|
#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); i < (min(a, b) + 1); ++i) {
long long int x = a / i;
if ((n - x) * i <= b) s = i;
}
cout << s << endl;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
sss << R"(
)";
MAIN();
return 0;
}
|
#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, a);
r = min(n, min(a, b));
for (int i = 1; i <= r; i++) {
long long int a1 = a / i;
if (n == i) continue;
long long int b1 = b / (n - i);
ans = pmax(ans, min(a1, b1));
}
cout << ans;
}
|
#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 dx[] = {0, -1, 0, 1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1};
const int dy[] = {-1, 0, 1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2};
int main() {
int n, a, b;
scanf("%d %d %d", &n, &a, &b);
int mn, ans = -1;
for (int i = 1; i < n; i++) {
int f = a / i;
int s = b / (n - i);
if (!f || !s) continue;
mn = min(f, s);
ans = max(ans, mn);
}
printf("%d\n", ans);
return 0;
}
|
#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 r;
}
int main() {
cin >> n >> a >> b;
cout << cautbin();
return 0;
}
|
#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, (b) / (n - i)));
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
|
#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; i <= n - 1; i++) max = MAX(MIN(a / i, b / (n - i)), max);
cout << max;
return 0;
}
|
#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 <= ed) {
md = (st + ed) / 2;
if (chk(md))
st = md + 1;
else
ed = md - 1;
}
if (chk(md))
cout << md << endl;
else
cout << md - 1 << endl;
}
return 0;
}
|
#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;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.