Cod sursa(job #2394894)
| Utilizator | Data | 2 aprilie 2019 08:37:41 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
typedef long long unsigned llu;
void euclid(llu a,llu b,llu &x,llu &y)
{
if(!b)
{
x=1;
y=0;
}else{
llu x0,y0;
euclid(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
}
}
int main()
{
llu a,n,x,y;
fin>>a>>n;
euclid(a,n,x,y);
while(x<=0)x+=n;
fout<<x;
return 0;
}
