Cod sursa(job #2039055)
| Utilizator | Data | 14 octombrie 2017 10:51:50 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <iostream>
#include <cstdio>
using namespace std;
long long a, n;
pair<long long, long long> euclid_extins(long long x, long long y)
{
if(y==0)
return {1,0};
auto p=euclid_extins(y, x%y);
return {p.second, p.first-(x/y)*p.second};
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
scanf("%lld %lld", &a, &n);
pair<long long, long long> r=euclid_extins(a, n);
while(r.first<0)
r.first+=n;
printf("%lld", r.first);
return 0;
}
