Maximum GCD UVA - 11827
1 #include2 #include 3 #include 4 using namespace std; 5 int gcd(int a,int b){ 6 return b ? gcd(b,a%b) : a; 7 } 8 int main(){ 9 int t;10 int a[105];11 char c;12 scanf("%d",&t);13 while(getchar() != '\n');14 while(t--){15 int cnt = 0;16 while((c = getchar()) != '\n'){17 if(c >= '0' && c <= '9'){18 ungetc(c,stdin);19 scanf("%d",&a[cnt++]);20 }21 }22 int maxx = 0;23 for(int i = 0; i < cnt-1; i++){24 for(int j = i+1; j < cnt; j++){25 int d = gcd(a[i],a[j]);26 if(d > maxx) maxx = d;27 }28 }29 printf("%d\n",maxx);30 }31 return 0;32 }