Cod sursa(job #1398390)

Utilizator Corneliu10Dumitru Corneliu Corneliu10 Data 24 martie 2015 10:28:57
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>
#define LL long long
using namespace std;
int gcd(LL &x,LL &y,int a,int b)
{
    if(!b)
    {
        x=1;
        y=0;
        return a;
    }
    else
    {
        int d=gcd(x,y,b,a%b);
        LL aux=x;
        x=y;
        y=aux - y * (a/b);
        return d;
    }
}
int main()
{
    int n;
    ifstream f("euclid3.in");
    ofstream g("euclid3.out");
    f>>n;
    for(int i=1;i<=n;i++)
    {
        int a,b,c,d;
        LL x,y;
        f>>a>>b>>c;
        d=gcd(x,y,a,b);
        if(c%d==0)
            g<<x*(c/d)<<" "<<y*(c/d)<<"\n";
        else
            g<<0<<" "<<0<<"\n";
    }
}