UVA 11827 Maximum GCD (input tips)

Source: Internet
Author: User

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&LT;GCD (Num[i],num[j])) mm=gcd (Num[i],num[j]); }} printf ("%d\n", MM); }    }    return 0;}

UVA 11827 Maximum GCD (input tips)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.