Cod sursa(job #2900395)

Utilizator zsoltzsoltDirirczi Zsolt zsoltzsolt Data 10 mai 2022 20:27:29
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int euclid_extins(int &x, int &y, int a, int b){
 
    if(b == 0){
        x = 1;
        y = 0;
       return a;
    }
    else{
        int x1 , y1;
        int t = euclid_extins(x1, y1, b, a%b);
        x = y1;
        y = x1 - y1 * (a / b);
        return t;
    }
}
int main(){
    
  int n;
  
  f >> n;
      
  for(int i = 0;i<n;++i){
    
  int a, b, c;
  f >> a >> b >> c;
  int x, y;
 
  euclid_extins(x,y,a,b);
  if(x < 0)
    x += b;
    
  if(y < 0)
    y += b;
 
  int t = euclid_extins(x,y,a,b);
  
  if(c%t == 0){
    int aux = c/t;
    g << x*aux << ' ' << y*aux << endl;
  }
  
  else g << 0 << ' ' << 0 << endl;
  }
}