1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| #include "bits/stdc++.h" #include "iomanip"
using namespace std;
#define fastIO() ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr) #define pb push_back #define judge(x) if (x) cout << "Yes" << endl; else cout << "No" << endl #define printlist(l, n) cout << "[ "; for(int (i)=0; (i)<(n); ++(i)) {cout << (l)[i] << " "; } cout << "]" << endl; #define loop(t) while (t-- > 0) #define all(a) a.begin(),a.end() #define rall(a) rbegin(a), rend(a) #define put(a) for (auto &_x: a) cin >> _x; #define space() cout<<endl
typedef long long ll; typedef pair<int, int> pii;
const int N = 2e5 + 5; const double eps = 1e-6; constexpr int mod = 1e9 + 7; constexpr int i32 = 0x3f3f3f3f;
using vi = std::vector<int>; using vvi = std::vector<vi>;
template<typename typC> bool isPrime(typC num) { if (num == 1 || num == 4)return 0; if (num == 2 || num == 3)return 1; if (num % 6 != 1 && num % 6 != 5)return 0; typC tmp = sqrt(num); for (int i = 5; i <= tmp; i += 6) if (num % i == 0 || num % (i + 2) == 0)return 0; return 1; }
bool isrp(int a, int b) { if (a == 1 || b == 1) return true; while (1) { int t = a % b; if (t == 0) { break; } else { a = b; b = t; } } if (b > 1) return false; else return true; }
int main() { fastIO(); int t; cin >> t; loop(t) { int n; cin >> n; vi a(n); put(a); int aa=-1,bb=-1; int ans=-1; int idx=1;
unordered_map<int, int> map;
for(int v:a){ if(v==1)ans=idx+idx; map[v]=idx++; }
vi b((int) map.size()); int ii=0; for(auto &it:map){ b[ii++]=it.first; }
for (int i = 0; i < b.size(); ++i) { aa=-1,bb=-1; for (int j = i; j < b.size(); ++j) { if(isrp(b[i],b[j])){ aa=max(aa,map[b[i]]),bb=max(bb,map[b[j]]); } } ans=max(ans,aa+bb); } cout<<ans<<endl; } }
|