UVA 11827 Maximum GCD Solution

Solve in C++:

///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE
///Islamic University,Bangladesh

#include<bits/stdc++.h>
using namespace std;
int fngcd(int p,int q)
{
    if(q==0)
        return p;
    else
        return fngcd(q,p%q);
}
int main()
{
    int i,j,ar[10000],n,gcd;
    cin>>n;
    getchar();
    string  s;
    while(n--)
    {
        getline(cin,s);
        stringstream ss(s);
        int k=0;
        while(ss>>ar[k])
            ++k;
        int gcd=0;
        for(i=0; i<k; i++)
        {
            for(j=i+1; j<k; j++)
            {
                gcd=max(gcd,fngcd(ar[i],ar[j]));

            }

        }
        cout<<gcd<<endl;

    }
    return 0;
}


No comments

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.