Ankit_132

C

Jun 6th, 2024
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. int LCM(int a, int b){
  7.     return (a*b)/__gcd(a, b);
  8. }
  9.  
  10. signed main(){
  11.    int t;
  12.    cin>>t;
  13.    while (t--){
  14.         int n;
  15.         cin >> n;
  16.         vector <int> v(n);
  17.        
  18.         for(int i=0; i<n; i++)
  19.             cin >> v[i];
  20.        
  21.         int x = v[0];
  22.         for(int i=1; i<n; i++)
  23.          x = LCM(x,v[i]);
  24.        
  25.         vector <int> a(n);
  26.         int sum = 0;
  27.         for(int i=0; i<n; i++)
  28.             a[i] = x/v[i];    
  29.        
  30.         if(accumulate(a.begin(), a.end(), 0ll) >= x){
  31.             cout<<"-1\n";
  32.             continue;
  33.         }
  34.        
  35.         for(auto x:a)
  36.             cout << x << " ";
  37.         cout << "\n";
  38.    }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment