Cod sursa(job #2146460)

Utilizator TTsandsSolomon Flavius TTsands Data 27 februarie 2018 23:38:43
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include<fstream>
using namespace std;

int EuclidExtins(int a, int b,int &x,int &y)
{
    if(b==0)
    {
        x=1;
        y=0;
        return a;
    }
    else
    {
        int x0,y0,d;
        d=EuclidExtins(b,a%b,x0,y0);
        x=y0;
        y=x0-(a/b)*y0;
        return d;

    }
}

int main()
{
    ifstream f("euclid3.in");
    ofstream g("euclid3.out");
    int n,a,b,c,d,x,y;
    int i;
    f>>n;
    for(i=1; i<=n; i++)
    {
        f>>a>>b>>c;
        d=EuclidExtins(a,b,x,y);
        if(c%d!=0)
            g<<0<<' '<<0<<'\n';
        else
            g<<x*(c/d)<<" "<<y*(c/d)<<'\n';

    }
    return 0;
}