A.GCD vs LCM
code:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define inf 0x3f3f3f3f
const int mod = 1e9 + 7;//998244353
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
using namespace std;
using i64 = long long;
void solve() {
int n;
scanf("%d", &n);
printf("%d %d %d %d\n", n - 3, 1, 1, 1);
}
int main(int argc, char** argv) {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int _t;
scanf("%d", &_t);
while (_t--) {
solve();
}
return 0;
}
B.Array Cloning Technique
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define inf 0x3f3f3f3f
const int mod = 1e9 + 7;//998244353
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
using namespace std;
using i64 = long long;
const int N = 1e5 + 10;
int a[N];
void solve() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
int cnt = 1, cnt1 = 1;
for (int i = 1; i < n; i++) {
if (a[i] == a[i - 1]) {
cnt1++;
continue;
}
else {
cnt = max(cnt, cnt1);
cnt1 = 1;
}
}
cnt = max(cnt, cnt1);
ll ans = 0;
int t = cnt;
while (t < n) {
if (n - t >= t) {
ans += (1 + t);
t *= 2;
}
else {
ans += (1 + (n - t));
break;
}
}
printf("%lld\n", ans);
}
int main(int argc, char** argv) {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int _t;
scanf("%d", &_t);
while (_t--) {
solve();
}
return 0;
}
C.Tree Infection
code:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define inf 0x3f3f3f3f
const int mod = 1e9 + 7;//998244353
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
using namespace std;
using i64 = long long;
const int N = 2e5 + 10;
int a[N], b[N], n;
bool cmp(int num1, int num2) {
return num1 >= num2;
}
bool check(int x) {
for (int i = 1; i <= n; i++) {
b[i] = 0;
}
int t = 0, tt = 0;
for (int i = 1; i <= x; i++) {
if (a[i]) {
b[i] = x - t;
t++;
}
}
if (t > x) return 0;
for (int i = 1; i <= n; i++) {
if (a[i] && a[i] > b[i]) {
tt += a[i] - b[i];
}
}
if (tt + t > x) return 0;
return 1;
}
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n + 1; i++) {
a[i] = 0;
}
a[1] = 1;
for (int i = 1; i < n; i++) {
int v;
scanf("%d", &v);
a[v + 1]++;
}
n += 1;
sort(a + 1, a + n + 1);
reverse(a + 1, a + n + 1);
int l = 0, r = n, ans = 0, mid = l + r >> 1;
while (l <= r) {
mid = l + r >> 1;
if (check(mid)) {
ans = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
printf("%d\n", ans);
}
int main(int argc, char** argv) {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int _t;
scanf("%d", &_t);
while (_t--) {
solve();
}
return 0;
}
D.GCD Guess
code:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define inf 0x3f3f3f3f
const int mod = 1e9 + 7;//998244353
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
using namespace std;
using i64 = long long;
void solve() {
int x, y, z, op;
x = 0;
for (int i = 0; i < 30 ;i++) {
z = (1 << i + 1);
y = (1 << i) - x;
cout << "? " << y << ' ' << y + z << endl;
cin >> op;
if (op == z) {
x |= (1 << i);
}
}
cout << "! " << x << endl;
}
int main(int argc, char** argv) {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int _t;
cin >> _t;
while (_t--) {
solve();
}
return 0;
}
E.MinimizOR