# Codeforces Round #483 (Div. 2) C, D

C. Finite or not?

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 100005;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int main() {
ll p, q, b;
int t;
scanf("%d", &t);
while(t--) {
scanf("%lld%lld%lld", &p, &q, &b);
ll g = gcd(p, q);
p /= g, q /= g;
b = gcd(q, b);
while(b != 1) {
while(q % b == 0) q /= b;
b = gcd(q, b);
}
puts(q == 1 ? "Finite" : "Infinite");
}
return 0;
}
D. XOR-pyramid

f(l, r) = f(l, r - 1)^f(l + 1, r)
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 5005;
int b[maxn];
int f[maxn][maxn];
int d[maxn][maxn];

int main() {
int n;
while(scanf("%d", &n) == 1) {
for(int i = 0; i < n; ++i) {
scanf("%d", &b[i]);
f[i][i] = b[i];
d[i][i] = b[i];
}
for(int i = 1; i < n; ++i) {
for(int l = 0; l < n - i; ++l) {
int r = l + i;
f[l][r] = f[l][r-1]^f[l+1][r];
//printf("f[%d][%d] = %d\n", l, r, f[l][r]);
}
}
for(int i = 1; i < n; ++i) {
for(int l = 0; l < n - i; ++l) {
int r = l + i;
d[l][r] = max({f[l][r], d[l][r - 1], d[l + 1][r]});
}
}
int q;
scanf("%d", &q);
while(q--) {
int l, r;
scanf("%d%d", &l, &r);
printf("%d\n", d[l-1][r-1]);
}
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120