#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t -- ) {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a == 0) {
if (b == 1) {
printf("2\nB 1\nA %d\n", -d);
} else {
printf("2\nB 3\nA %d\n", d);
}
} else if (b == 0) {
if (a == -1) {
printf("3\nB 1\nA %d\nB 1\n", c);
} else {
printf("3\nB 1\nA %d\nB 3\n", -c);
}
} else if (c == 0) {
if (a == 1) {
printf("1\nA %d\n", b);
} else {
printf("2\nA %d\nB 2\n", -b);
}
} else {
if (b == 1) {
printf("2\nA %d\nB 1\n", -a);
} else {
printf("2\nA %d\nB 3\n", a);
}
}
}
return 0;
}
C. Countdown
#include <bits/stdc++.h>
using namespace std;
int main() {
cout << 189<< endl;
return 0;
}
D. Divide
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e7 + 10;
int v[N], prime[N];
int m;
void init() {
int n = 1e7;
for (int i = 2; i <= n; i ++ ) {
if (v[i] == 0) {
v[i] = i;
prime[++ m] = i;
}
for (int j = 1; j <= m; j ++ ) {
if (prime[j] > v[i] || prime[j] > n / i) break;
v[i * prime[j]] = prime[j];
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
init();
while (t -- ) {
int l, r, a, b;
cin >> l >> r >> a >> b;
bool ok = 1;
for (int i = 1; i <= m; i ++ ) {
if (prime[i] > r) break;
LL cnt1 = 0, cnt2 = 0;
for (LL j = prime[i]; j <= max(r, b); j *= prime[i]) {
cnt1 += r / j - (l - 1) / j;
cnt2 += b / j - (a - 1) / j;
}
if (cnt1 > cnt2) {
ok = 0;
break;
}
}
if (ok) puts("Yes");
else puts("No");
}
return 0;
}
E. Edge Game
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
typedef vector<int> VI;
const int N = 1e5 + 10;
bool st[N];
int ans;
VI edg[N];
void bfs(int a, int b) {
queue<PII> q;
q.push({a, 0});
st[a] = 1;
while (q.size()) {
auto t = q.front(); q.pop();
for (auto v : edg[t.FI]) {
if (st[v]) continue;
if (v == b) {
ans = t.SE + 1;
return;
}
st[v] = 1;
q.push({v, t.SE + 1});
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i < n; i ++ ) {
int u, v;
cin >> u >> v;
edg[u].PB(v), edg[v].PB(u);
}
int a, b;
cin >> a >> b;
bfs(a, b);
if (ans & 1) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
G. Group QQ Speed
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t -- ) {
int n, m;
cin >> n >> m;
if (1 == m) cout << n + 1 << endl;
else if (m == n) cout << 2 << endl;
else cout << 3 << endl;
}
return 0;
}
I. I Love You
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s, t;
cin >> s >> t;
int i = 0, j = 0;
for (; i < s.size(); i ++ ) {
if (s[i] == t[j]) j ++;
}
if (j == t.size()) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
J. Just the Chosen One
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long double f[N];
void init() {
f[0] = f[1] = 0;
for (int i = 2; i < N; i ++ )
f[i] = f[i - 1] + 1.0 / i;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int n, m, k;
cin >> n >> m >> k;
double ans = 0;
if (m >= k) {
ans += m - k;
k = m;
}
if (n < N && k < N)
ans += (double) m * (f[n] - f[k - 1]);
else
ans += (double) m * (log(n) - log(k - 1));
printf("%9lf", ans);
return 0;
}
K. K-Primes
#include <bits/stdc++.h>
using namespace std;
int main() {
int l, k;
cin >> l >> k;
if (l == 2 && k <= 3) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}