Cod sursa(job #1673885)

Utilizator KOzarmOvidiu Badea KOzarm Data 4 aprilie 2016 10:42:20
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <fstream>

using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int n,i,a,b,c,x,y,tmp;
void euext(int a,int b,int &x, int &y)
{
    if(b==0)
    {
        x=1;y=0;
    }
    else
    {
        euext(b,a%b,x,y);
        int aux=x;
        x=y;
        y=aux-(a/b)*y;
    }
}
int main()
{
    fin>>n;
    for(i=1;i<=n;i++)
    {
        fin>>a>>b>>c;
        euext(a,b,x,y);
        if(c%(a*x+b*y)==0)
        {
            tmp=c/(a*x+b*y);
            fout<<x*tmp<<" "<<y*tmp<<"\n";
        }
        else
            fout<<"0 0\n";
    }
    return 0;
}