啊,这周又是一堆的作业,只打了一场比赛,没想到遇到了国人的数论专场, 打着打着就不会了,😔
#include <bits/stdc++.h> using namespace std; int sdiv(int n){ for(int i = 2; i <= sqrt(n); i++){ if(n % i == 0) return i; } return n; } int main(){ int n; scanf("%d",&n); while(n--){ int k, t; scanf("%d%d",&k,&t); if(sdiv(k) % 2 == 1){ k += sdiv(k); k += (t-1)*2; } else { k += t *2; } printf("%d\n",k); } return 0; }
# include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector <int> a(n + 1), dp(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } int answer = 0; for (int i = 1; i <= n; i++) { int mx = 0; for (int j = 1; j * j <= i; j++) { if (i % j == 0) { if (a[j] < a[i]) mx = max(mx, dp[j]); if (a[i / j] < a[i]) mx = max(mx, dp[i / j]); } } dp[i] = mx + 1; answer = max(answer, dp[i]); } cout << answer << endl; } int main() { int tt = 1; cin >> tt; while (tt--) solve(); }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> pre(n + 1); for (int i = 0; i < n; i++) { pre[i + 1] = __gcd(pre[i], a[i]); } vector<int> suf(n + 1); for (int i = n - 1; i >= 0; i--) { suf[i] = __gcd(suf[i + 1], a[i]); } long long ans = 1; for (int i = 0; i < n; i++) { int x = __gcd(pre[i], suf[i + 1]); ans = ans / __gcd(ans, (long long) x) * x; } cout << ans << '\n'; return 0; }