Cod sursa(job #1115811)

Utilizator olly2204Olly2204 olly2204 Data 22 februarie 2014 01:43:41
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
//#include "stdafx.h"

 //references
//http://www.infoarena.ro/algoritmul-lui-euclid

#include <fstream>
#include <iostream>

std::ifstream in("euclid3.in");
std::ofstream out("euclid3.out");

void euclid(long a, long b, long c, long* x, long *y)
{
    if (b==0)
    {
        *x = 1;
        *y = 0;
    }
    else 
    {
        long x0, y0;
        euclid(b, a % b, c, &x0, &y0);
        *x = y0;
        *y = x0 = (a/b) * y0;
    }
}

int main()
{
    int T;
    in >> T;

    for (int i = 0; i < T; i++)
    {
        long a,b,c;
        in >> a >> b >> c;
        long x, y = 0;
        euclid(a,b,c, &x, &y);

        out << x << " " << y;
    }
}