代码在对1特判的时候要用 if(cnt.count(1)&&cnt[1]>=2) 如果直接cnt[1]>=2 会影响后面cnt.count(1)的判断(即使没有1 代码也会cnt[1] = 1)

可以用[100,100,100] 试一下 ac代码如下: #include<bits/stdc++.h> using namespace std; #define int long long #define yes cout<<"YES\n" #define no cout<<"NO\n"

const int LIM = 1e9; int qpow(int a,int b){ int ans = 1ll; while(b){ if(b & 1)ans = ans * a; b >>= 1;a *= a; if(ans > 1e9) return 1e9+1; } return ans; }

void solve() { int n;cin>>n; vector a(n); unordered_map<int,int> cnt; for(int i=0;i<n;i++) { cin>>a[i]; cnt[a[i]]++; } if(cnt.count(1)&&cnt[1]>=2){yes;return;} if(cnt.count(1)) { for(auto &p:cnt) if(p.second>=2){yes;return;} } sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end());
int mx = a.back(); for(int i = 0; i < a.size(); i++)
{ int x = a[i]; if(x == 1) continue; if(x * x > mx) break; for(int j = 0; j < a.size(); j++) { int y = a[j]; if(y == 1) continue; if(y >= 30) break; int val = qpow(x, y); if(val > mx) break; if(cnt.count(val)){ yes; return; } } } no; }

signed main() { ios::sync_with_stdio(0);cin.tie(0); int T;cin>>T; while(T--) solve(); return 0; }