Cod sursa(job #2758871)

Utilizator lahayonTester lahayon Data 13 iunie 2021 19:30:36
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>
	
 
	
using namespace std;
	
 
	
void euclid(int A, int B, int& x, int& y){
	
    if(B == 0){
	
        x = 1;
	
        y = 0;
	
    }
	
    else{
	
        int _x, _y;
	
        euclid(B, A % B, _x, _y);
	
        x = _y;
	
        y = _x - (A / B) * _y;
	
    }
	
 
	
}
	
 
	
int main()
	
{
	
    ifstream cin("inversmodular.in");
	
    ofstream cout("inversmodular.out");
	
         
	
    int A, N, x, y;
	
    cin >> A >> N;
	
 
	
    euclid(A, N, x, y);
	
    if(x < 0)
	
        x = x + ((x / N) + 1) * N;
	
 
	
    cout << x;
	
    
	
 
	
    cin.close();
	
    cout.close();
	
 
	
    return 0;
	
}