Cod sursa(job #1323229)

Utilizator tibiletsKoos Tiberiu Iosif tibilets Data 20 ianuarie 2015 20:22:05
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include <fstream>
using namespace std;
void euclid(int a, int b, int *d, int *x, int *y)
{
    if (b == 0) {
        *d = a;
        *x = 1;
        *y = 0;
    } else {
        int x0, y0;
        euclid(b, a % b, d, &x0, &y0);
        *x = y0;
        *y = x0 - (a / b) * y0;
    }
}

int main()
{ifstream f("euclid3.in");
ofstream g("euclid3.out");
int a,b,c,d,i;
for(f>>i;i;--i)
{f>>a>>b>>c;
euclid(a,b,&d,&a,&b);
if(c%d==0)
    g<<a*c/d<<' '<<b*c/d<<'\n';
    else g<<0<<' '<<0<<'\n';
}
}