Minimum Sum

Language : C++
(NOTE : Try a few times yourself before moving to the solution)


#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;
typedef long long int ll;


int main()
{


 ll t;
 cin>>t;
 while(t--)
 {

     ll n;
     cin>>n;
     vector<ll>v(n);
     for(ll i=0;i < n;i++)
     {
         cin>>v[i];


     }


     ll res =__gcd(v[0],v[1]);
     for(ll i=2;i < n;i++)
     {

         res=__gcd(res,v[i]);

     }
  cout << (res*n) << endl;




 }
 return 0;
}

No comments:

Post a Comment