CF-1183F

题意

给 $n$ 个数,选至多 $3$ 个,且两两不为倍数关系,问最大值是多少

题解

排序,若最大值不取 $a_n$,那只有一种可能 $\frac 1 2 a_n ,\frac 1 3 a_n,\frac 1 5 a_n $,因为如果最大值包含不为 a_n 的因子,那么显然取 a_n 更优。易证,若取 $a_n$ ,一定会取 不为 $a_n$ 因子的最大值

代码

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
#include <bits/stdc++.h>
using namespace std;
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define forr(i, r, l) for (int i = r; i >= l; i--)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define fro1(i, n) for (int i = 1; i <= n; i++)
#define for0(i, n) for (int i = 0; i < n; i++)
#define fro0(i, n) for (int i = 0; i < n; i++)
#define meminf(a) memset(a, inf, sizeof(a))
#define mem_1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))
#define memcp(a,b) memcpy(a,b,sizeof(b))
#define oper(type) bool operator <(const type y)const
#define mp make_pair
#define pu_b push_back
#define pu_f push_front
#define po_b pop_back
#define po_f pop_front
#define fi first
#define se second
#define whiel while
#define retrun return
typedef pair<long long, long long> pll;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vii;
typedef long double db;
typedef long long ll;
typedef int itn;
int in(int &a,int &b,int &c,int &d){return scanf("%d%d%d%d",&a,&b,&c,&d);}
int in(int &a,int &b,int &c){return scanf("%d%d%d",&a,&b,&c);}
int in(int &a,int &b){return scanf("%d%d",&a,&b);}
int in(ll &a){return scanf("%lld",&a);}
int in(int &a){return scanf("%d",&a);}
int in(char *s){return scanf("%s",s);}
int in(char &s){return scanf("%c",&s);}
int in(db &a){return scanf("%Lf",&a);}
void out(int a){printf("%d ",a);}
void outln(int a){printf("%d\n",a);}
void out(ll a){printf("%lld ",a);}
void outln(ll a){printf("%lld\n",a);}
const db pi = acos((db)-1);
const ll inf =0x3f3f3f3f;
const db eps = 1e-8;
const int N = 2.1e5;
const ll mod = 1e9+7;
int sign(db a) { return a < -eps ? -1 : a > eps;}
int db_cmp(db a, db b){ return sign(a-b); }

int a[N];
unordered_set<int>s;
int main() {
int q,n;
in(q);
while(q--){
in(n);
for0(i,n){
in(a[i]);
s.insert(a[i]);
}
sort(a,a+n);
n=unique(a,a+n)-a;
int maxx=a[n-1];
int tmp=maxx;
if(maxx%2==0&&maxx%3==0&&maxx%5==0&&s.count(maxx/2)&&s.count(maxx/3)&&s.count(maxx/5)){
maxx=maxx/30*31;
}
for(int i=n-2;i>=0;i--){
if(tmp%a[i]){
for(int j=i-1;j>=0;j--){
if(tmp%a[j]&&a[i]%a[j]){
tmp+=a[j];
break;
}

}
tmp+=a[i];
break;
}
}
outln(max(maxx,tmp));
s.clear();
}
return 0;
}