Cod sursa(job #2524187)
| Utilizator | Data | 15 ianuarie 2020 10:26:15 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <bits/stdc++.h>
using namespace std;
string file="inversmodular";
ifstream fin(file+".in");
ofstream fout(file+".out");
typedef long long ll;
int N,A;
ll inv,ins;
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);
}
}
int main()
{
fin>>A>>N;
gcd(inv,ins,A,N);
if(inv<=0){
inv=N+inv%N;
}
fout<<inv;
return 0;
}
