l比赛题目链接
#include
const int MAXN = 1e5 + 10;
typedef long long ll;
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
ll n, k;
cin >> n >> k;
if (n & 1) {
for (int i = 3; ; i++) {
if (n % i == 0) {
n += i;
break;
}
}
n = n + (k - 1) * 2ll;
}
else {
n = n + k * 2ll;
}
cout << n << endl;
}
}
#include
typedef long long ll;
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int dp[MAXN];
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
dp[i] = 1;
}
int ret = 1;
for (int i = 1; i <= n; i++) {
for (int j = 2 * i; j <= n; j += i) {
if (a[j] > a[i]) {
dp[j] = max(dp[j], dp[i] + 1);
ret = max(ret, dp[j]);
}
}
}
cout << ret << endl;
}
}
#include
const int MAXN = 1e5 + 10;
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
int dp[N];
const int INF = 0x3f3f3f3f;
#define pa pair
const int maxn = 1e6 + 1000;
int prime[maxn] = { 0 }, phi[maxn] = { 0 }, tot = 0;
void euler() {
phi[1] = 1;
for (int i = 2; i < maxn; i++) {
if (!phi[i]) {
prime[tot++] = i;
phi[i] = i - 1;
}
for (int j = 0; j < tot && i * prime[j] < maxn; j++) {
if (i % prime[j] == 0) {
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
phi[i * prime[j]] = phi[i] * phi[prime[j]];
}
}
}
map<int, vector<int>> ma;
#define pa pair
vector<pa> factor;
void init(int n) {
factor.clear();
for (int i = 0; prime[i] * prime[i] <= n && i < tot; i++) {
if (n % prime[i] == 0) {
factor.emplace_back(prime[i], 0);
for (; n % prime[i] == 0; n /= prime[i]) factor.back().second++;
}
}
if (n > 1) factor.emplace_back(n, 1);
for (auto it : factor) {
ma[it.first].push_back(it.second);
}
}
int arr[MAXN];
int main() {
euler();
cin.tie(0);
ios::sync_with_stdio(0);
int n;
while (cin >> n) {
ma.clear();
for (int i = 1; i <= n; i++) {
cin >> arr[i];
init(arr[i]);
}
ll ret = 1;
for (auto& it : ma) {
int tt = 0;
if (it.second.size() == n) {
sort(it.second.begin(), it.second.end());
tt = it.second[1];
}
else if (int(it.second.size()) == n - 1) {
sort(it.second.begin(), it.second.end());
tt = it.second[0];
}
for (int i = 0; i < tt; i++) ret *= ll(it.first);
}
cout << ret << endl;
}
}
#include
typedef long long ll;
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int main() {
int T;
cin >> T;
while (T--) {
int n, k;
cin >> n >> k;
int kf = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == k) kf = 1;
}
if (n == 1 || n == 2) {
if (n == 2) sort(a, a + 2);
if (a[0] == k) cout << "yes\n";
else cout << "no\n";
}
else {
int f = 0;
for (int i = 2; i < n; i++) {
vector<int> t = { a[i], a[i - 1],a[i - 2] };
sort(t.begin(), t.end());
if (t[1] >= k && t[2] >= k) {
f = 1;
break;
}
}
if (f && kf) cout << "yes\n";
else cout << "no\n";
}
}
}
#include
typedef long long ll;
using namespace std;
const int MAXN = 1e3 + 10;
const ll INF = 2e18;
char ma[MAXN][MAXN];
ll step[MAXN][MAXN];
struct nod{ int x, y; };
int dx[] = { 0,0,-1,1 };
int dy[] = { -1,1,0,0 };
int n, m, q;
void bfs() {
queue<nod> Q;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
step[i][j] = INF;
for (int t = 0; t < 4; t++) {
int ni = i + dx[t];
int nj = j + dy[t];
if (ni >= 0 && ni < n && nj >= 0 && nj < m
&& ma[ni][nj] == ma[i][j]) {
Q.push({ i,j });
step[i][j] = 0;
break;
}
}
}
}
while (!Q.empty()) {
nod cur = Q.front();
Q.pop();
for (int i = 0; i < 4; i++) {
int nx = cur.x + dx[i];
int ny = cur.y + dy[i];
if (nx >= 0 && nx < n && ny >= 0 && ny < m && step[nx][ny] == INF) {
step[nx][ny] = step[cur.x][cur.y] + 1;
Q.push({ nx, ny });
}
}
}
}
int main() {
cin >> n >> m >> q;
for (int i = 0; i < n; i++) cin >> ma[i];
bfs();
while (q--) {
int x, y;
ll t;
cin >> x >> y >> t;
x--, y--;
if (step[x][y] == INF || step[x][y] > t) cout << ma[x][y] << endl;
else {
t -= step[x][y];
if (t & 1ll) cout << 1 - int(ma[x][y] - '0') << endl;
else cout << ma[x][y] << endl;
}
}
}