https://mirror.codeforces.com/contest/1979/problem/C↵
↵
↵
https://mirror.codeforces.com/contest/1979/submission/266588454↵
↵
↵
#include <bits/stdc++.h>↵
↵
using namespace std;↵
↵
#define M 1e9+7↵
#define pb push_back↵
#define int long long int↵
#define push push_back↵
#define pop pop_back↵
#define yes cout << "yes" << endl↵
#define no cout << "no" << endl↵
↵
#define all(v) v.begin(),v.end()↵
#define rall(v) v.rbegin(),v.rend()↵
#define vsort(v) sort(all(v))↵
#define vrsort(v) sort(rall(v))↵
#define vreverse(v) reverse(all(v))↵
#define vmin(v) *min_element(all(v));↵
#define vmax(v) *max_element(all(v));↵
#define vmini(v) min_element(all(v)) — v.begin()↵
#define vmaxi(v) max_element(all(v)) — v.begin()↵
//#define vsum(v) accumulate(all(v), 0 * 1LL)↵
//For descending just change the sign↵
bool comp1(pair<int,int> p1,pair<int,int> p2){↵
return p1.first<p2.first;↵
}↵
bool comp2(pair<int,int> p1,pair<int,int> p2){↵
return p1.second<p2.second;↵
}↵
↵
template <typename T>↵
std::istream &operator>>(std::istream &in, std::vector<T> &v){↵
for (int i = 0; i < v.size(); i++){↵
in >> v[i];↵
}↵
return in;↵
}↵
↵
template <typename T>↵
ostream &operator<<(ostream &os, const vector<T> &v){↵
for (int i = 0; i < v.size(); ++i){↵
os << v[i] << ' ';↵
}↵
os << endl;↵
return os;↵
}↵
↵
// Function to calculate GCD of two numbers↵
int gcd(int a, int b) {↵
while (b != 0) {↵
int temp = b;↵
b = a % b;↵
a = temp;↵
}↵
return a;↵
}↵
↵
// Function to calculate LCM of two numbers↵
int lcm(int a, int b) {↵
return std::abs(a * b) / gcd(a, b);↵
}↵
↵
void solve(){↵
int n;↵
cin>>n;↵
vector<int>arr(n);↵
cin>>arr;↵
int lccm = accumulate(arr.begin(), arr.end(), 1, lcm);↵
// for(int i=0;i<n;i++)↵
// {↵
// if(lccm==arr[i])↵
// {↵
// cout<<-1<<endl;↵
// return;↵
// }↵
// }↵
int sol=0;↵
for(int i=0;i<n;i++)↵
{↵
sol+=lccm/arr[i];↵
}↵
if(sol==lccm)↵
{↵
cout<<-1<<endl;↵
return;↵
}↵
for(int i=0;i<n;i++)↵
{↵
cout<<lccm/arr[i]<<" ";↵
↵
↵
}↵
cout<<endl;↵
↵
↵
}↵
↵
signed main(){↵
ios::sync_with_stdio(0);↵
cin.tie(0);↵
int t=1;↵
cin >> t;↵
while(t--){↵
solve();↵
//solve() ? yes : no;↵
}↵
}↵
/*// Function to calculate GCD of two numbers↵
int gcd(int a, int b) {↵
while (b != 0) {↵
int temp = b;↵
b = a % b;↵
a = temp;↵
}↵
return a;↵
}↵
↵
// Function to calculate LCM of two numbers↵
int lcm(int a, int b) {↵
return std::abs(a * b) / gcd(a, b);↵
}↵
↵
int main() {↵
std::vector<int> nums = {12, 18, 24, 36};↵
↵
// Using std::accumulate and custom lcm function to find the LCM of the vector↵
int result = accumulate(nums.begin(), nums.end(), 1, lcm);↵
↵
cout << "LCM of the vector is " << result << endl;↵
↵
return 0;↵
}↵
*/