Cod sursa(job #1714068)
Utilizator | Data | 7 iunie 2016 12:20:08 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.28 kb |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void gcd(ll &x,ll &y,ll a,ll b){
if(!b) x = 1, y = 0;
else{
gcd(x,y,b,a%b);
ll aux = x;
x = y;
y = aux - y*(a/b);
}
}
ll N,A,X,Y;
int main(){
cin >> A >> N;
gcd(X,Y,A,N);
while(X <= 0) X=N+X%N;
cout << X;
}