Cod sursa(job #1099164)

Utilizator SCBbestofSocaciu-Cumpanasu Bogdan SCBbestof Data 5 februarie 2014 16:55:12
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

long long a, b, c, x, y, t;

inline int cmmdc(int a,int b)
{
    int r;
    while(b!=0)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
inline void Euclid(long long a, long long b, long long &x, long long &y){
    long long x0, y0;
    if(!b)  {x=1; y=0; return;}
    else    Euclid(b, a%b, x0, y0);
    x=y0;
    y=x0-y0*(a/b);
}
int main()
{
    int N;
    f>>N;
    for(int i = 0 ; i < N; ++i)
    {
        f>>a>>b>>c;
        int d = cmmdc(a,b);
        if(c%d!=0)
        {
            g<<"0 0"<<endl;
        }
        else
        {
            Euclid(a, b, x, y);
            g<<x*c/d<<" "<<y*c/d<<endl;
        }
    }
    return 0;
}