Cod sursa(job #1799604)
Utilizator | Data | 6 noiembrie 2016 15:55:55 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <bits/stdc++.h>
std::ifstream in("inversmodular.in");
std::ofstream out("inversmodular.out");
long long x,y,a,n;
void eucl(long long a,long long b){
if(!b){
x=1;
y=0;
return;
}
eucl(b,a%b);
int tmp=y;
y=x-(a/b)*y;
x=tmp;
}
int main()
{
in>>a>>n;
eucl (a,n);
while(x<0)x+=n;
out<<x;
return 0;
}