Cod sursa(job #1311109)

Utilizator radu_uniculeu sunt radu radu_unicul Data 7 ianuarie 2015 18:58:31
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include<iostream>
#include<fstream>
#include<algorithm>

using namespace std;
long long eu(long long a,long long b)
{
    int r=a%b;
    while(r)
    {
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
void euex(long long a,long long b,long long &x,long long &y)
{
    if(b==0)
    {
        x=1;
        y=0;
    }
    else
    {
        long long x0,y0;
        euex(b,a%b,x0,y0);
        x=y0;
        y=x0-x*(a/b);
    }
}
int main()
{
    ifstream si;
    si.open("euclid3.in");

    ofstream so;
    so.open("euclid3.out");
int t;
si>>t;
while(t--)
{
    long long a,b,c;
    si>>a>>b>>c;
    if(b==0)
    {
        if(c%a==0)
            so<<c/a<<' '<<0<<'\n';
        else
            so<<0<<' '<<0<<endl;

    }
    else
    {
    long long d=eu(a,b);
    if(c%d!=0)
        so<<0<<' '<<0<<'\n';
    else
    {
        long long x,y;
        euex(a,b,x,y);
        so<<x*(c/d)<<' '<<y*(c/d)<<'\n';
    }
    }
}
}