Test instructions: For a given set of numbers, the maximum value of 22 gcd in the number of groups is obtained;
Idea: Simple GCD, the highlight is that the number of each group is not provided, so the need to read in is to make judgments;
#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;#defineEPS 1e-5intt,i,j,k,num[50010],b,flag,shu,mm;intgcdintAintb) { intC; C=a%b; while(c) {a=b;b=c;c=a%b; } returnb;}intMain () {CharC; while(SCANF ("%d", &t)! =EOF) { while(t--) {memset (num,0,sizeof(num)); Shu=0; mm=0; while(1) {scanf ("%d", &num[shu++]); while((C=getchar ()) = =' ');//Read SpaceUNGETC (C,stdin);//returns a character to the input stream, placing the number in the array num if(c=='\ n') Break;//line break Exit} Shu--; for(i=0; i<=shu;i++) { for(j=i+1; j<=shu;j++) { if(MM<GCD (Num[i],num[j])) mm=gcd (Num[i],num[j]); }} printf ("%d\n", MM); } } return 0;}
UVA 11827 Maximum GCD (input tips)