WAon#5求调
查看原帖
WAon#5求调
743373
Vitamin_B楼主2024/3/5 22:17

rt,总是误认为有解

# include <bits/stdc++.h>

# define ffor(i,name) \
	for (auto i = name.begin (); i != name.end (); ++ i)

using namespace std;

typedef long long ll;

typedef pair <int, int> pii;

int t, n, j;

ll ans, a[305];

int main () {

	ios::sync_with_stdio (0);

	cin.tie (0);

	cout.tie (0);

	cin >> t;
	
	while (t --) {
	    
	    cin >> n;
	    
	    for (int i = 1; i <= n; ++ i)
	        cin >> a[i];
	    
	    j = 1;
	    
	    sort (a + 1, a + 1 + n);
	    
	    ans = a[1] * a[n];
	    
	    for (ll i = 2; i * i <= ans; ++ i)
	        if (! (ans % i))
	            if (a[j] != i || a[n - j + 1] != ans / i) {
	                
	                cout << "-1\n";
	                
	                goto there;
	                
	            } else
	                ++ j;
	   
        cout << ans << '\n';
        
        there:;
	    
	}

	return 0;

}
2024/3/5 22:17
加载中...