Codeforces Round #680 (Div. 2, based on Moscow Team Olympiad) A ~ C
A
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define fi firsqt
#define se second
#define inf 0x3f3f3f3f
const int N = 55;
int a[N], b[N];
int main() {
IO;
int _;
cin >> _;
while (_--) {
int n, x;
cin >> n >> x;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) cin >> b[i];
int flag = 1;
for (int i = 0; i < n; ++i)
if (a[i] + b[n - 1 - i] > x) {
flag = 0;
break;
}
if (flag) puts("YES");
else puts("NO");
}
return 0;
}
B
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define fi firsqt
#define se second
#define inf 0x3f3f3f3f
const int N = 55;
int a[N], b[N];
int main() {
IO;
int _;
cin >> _;
while (_--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
int ans = max(a + b, c + d);
cout << ans << endl;
}
return 0;
}
C
参考于 : https://www.cnblogs.com/zwjzwj/p/13912656.html
题意
给出两个数p, q, 找到最大的x, 使得x是p的因子且x不是q的倍数.
思路
分两种情况 :
-
: 如果q不是p的因子, 答案就是p.
-
: 当q是p的因子时, 去枚举q的质因子, 得到该质因子在q中最高次, 少去一次后乘上p将该质因子除干净得到的数. 例如 : 对于质因子i, 设i在p中最高有a次, 在q中最高有b次.
\[x = \frac{p}{i^a} * i^{b-1} = p * i^{b - 1 - a}
\]
注 : 因为p是q的倍数所以必定满足a >= b.
代码
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define fi firsqt
#define se second
#define inf 0x3f3f3f3f
ll qpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = res * a;
b >>= 1;
a = a * a;
}
return res;
}
int main() {
IO;
int _;
cin >> _;
while (_--) {
ll p, q;
cin >> p >> q;
ll ans = 0;
if (p % q != 0) ans = p;
else {
for (int i = 2; i <= q / i; ++i) {
if (q % i == 0) {
int cnt = 0;
while (q % i == 0) q /= i, ++cnt;
ll x = p;
while (x % i == 0) x /= i;
ans = max(ans, x * qpow(i, cnt - 1));
}
}
if (q > 1) {
ll x = p;
while (x % q == 0) x /= q;
ans = max(ans, x);
}
}
cout << ans << endl;
}
return 0;
}