Cod sursa(job #2476639)

Utilizator AntoniuFicAntoniu Ficard AntoniuFic Data 19 octombrie 2019 10:46:25
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>

using namespace std;

long long A, B, C;

bool euclid(long long a, long long b, long long &x, long long &y){
    if(b == 0){
        y = 0;
        x = 1;
        return C % a == 0;
    }
    if(euclid(b, a%b, x, y)){
        long long x1 = x, y1 = y;
        y = x1 - a / b * y1;
        x = y1;
        return true;
    }
    return false;
}

int main() {
    ifstream f("euclid3.in");
    ofstream g("euclid3.out");
    int n;
    f>>n;
    for (int i = 0; i < n; ++i) {
        f>>A>>B>>C;
        long long x, y;
        if(euclid(A, B, x, y))
            g<<x<<" "<<y<<"\n";
        else g<<0<<" "<<0<<"\n";
    }
    return 0;
}