T3000

Untitled

Jan 7th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.   long long n1;
  8.  
  9.   cin >> n1;
  10.   for (int i = 0; i < n1; i++)
  11.   {
  12.     long long r = 1;
  13.     long long w;
  14.     cin >> w;
  15.     for (int j = 0; j < w; j++)
  16.     {
  17.       long long a;
  18.       cin >> a;
  19.       if (r <= 1000000000 && r >= 0)
  20.       {
  21.         long long b = r;
  22.         long long m = min(a, b);
  23.         long long n = max(a, b);
  24.         while (m != 0)
  25.         {
  26.  
  27.           long long tmp = n % m;
  28.           n = m;
  29.           m = tmp;
  30.         }
  31.         r = a / n * b;
  32.       }
  33.     }
  34.  
  35.     if (r > 1000000000 || r <= 0)
  36.     {
  37.       cout << "More than a billion." << endl;
  38.     }
  39.     else
  40.     {
  41.       cout << r << endl;
  42.     }
  43.   }
  44.  
  45.   return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment