Last active
November 22, 2015 17:57
-
-
Save ronalddas/059d2a16a58e3c8e802a to your computer and use it in GitHub Desktop.
Sereja has an array A of N positive integers : A[1], A[2], A[3], ... , A[N]. In a single operation on the array, he performs the following two steps : Pick two indices i, j s.t. A[i] > A[j] A[i] -= A[j] Sereja can apply these operations any number of times (possibly zero), such that the sum of resulting elements of the array is as small as possi…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(void) | |
{ | |
int tcn=0,sum[10],sm=0,i=0,j=0,k=0,no=0,a[100000]; | |
//No. of tc; | |
do{ | |
cin>>tcn; | |
}while(tcn < 1 || tcn > 10); | |
for(k =0; k < tcn ; k++) | |
{ | |
//No.of elementes in array | |
cin>>no; | |
for(i = 0 ; i < no; i++) | |
{ | |
cin>>a[i]; | |
} | |
for(i =0 ; i < no; i ++) | |
{ | |
for( j=0 ; j < no; j++) | |
{ | |
if(a[i]>a[j]) | |
a[i]-=a[j]; | |
} | |
} | |
for ( i =0 ; i < no; i++) | |
{ | |
//cout<<a[i]<<" "; | |
sm+=a[i]; | |
} | |
sum[k]=sm; | |
sm=0; | |
} | |
for ( k = 0 ; k < tcn; k++) | |
cout<<sum[k]<<endl; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment