-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchefchick.cpp
More file actions
executable file
·57 lines (49 loc) · 868 Bytes
/
chefchick.cpp
File metadata and controls
executable file
·57 lines (49 loc) · 868 Bytes
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
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll int eugcd(ll int m, ll int n)
{
ll int t;
while(n!=0)
{
t=m%n;
m=n;
n=t;
}
return m;
}
int main(void)
{
ll int t;
cin>>t;
for(ll int x=0; x<t; x++)
{
ll int n, upper_lim, pen_upper_lim=0LL, ans=0, min_elem=INT_MAX;
cin>>n;
ll int a[n];
for(ll int i=0; i<n; i++)
{
cin>>a[i];
if(min_elem>a[i])
min_elem=a[i];
}
ll int temp=a[0];
for(ll int i=1; i<n; i++)
{
ll int ans_gcd;
if(temp>a[i])
ans_gcd=__gcd(temp, a[i]);
else
ans_gcd=__gcd(a[i], temp);
upper_lim=(temp*a[i]/ans_gcd);
temp=upper_lim;
}
//cout<<upper_lim<<"\n";
pen_upper_lim=( (upper_lim/min_elem) - 1 )*min_elem;
//cout<<pen_upper_lim<<"\n";
if(ans<(upper_lim-pen_upper_lim))
ans=(upper_lim-pen_upper_lim);
cout<<ans<<"\n";
}
return 0;
}