UVA 10104 Euclid Problem Solution

///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd Batch
///Islamic University,Bangladesh
#include<iostream>
using namespace std;
long long   egcd(long long  a,long long b,long long *x,long long *y)
{
    if(b==0)
    {
        *x=1;
        *y=0;
        return a;
    }

     long long x1,y1;
    long long gcd=egcd(b,a%b,&x1,&y1);

    *y=x1-(a/b)*y1;
    *x=y1;
    return gcd;
}
int main()
{

    long long x,y,a,b,g;
    while(cin>>a>>b)
    {
    g=egcd(a,b,&x,&y);
    cout<<x<<" "<<y<<" "<<g<<endl;

}
}

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.