Cod sursa(job #1435896)
| Utilizator | Data | 14 mai 2015 19:01:17 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include<fstream>
#include<vector>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
#define ll long long
ll a,n,x,y;
ll gcd(ll a, ll b, ll &x, ll &y){
if (!b) return x=1,y=0,a;
ll x1,y1;
ll g=gcd(b,a%b,x1,y1);
x=y1;
y=x1-y1*(a/b);
return g;
}
int main()
{
cin>>a>>n;
ll g=gcd(a,n,x,y);
x=(x%n+n)%n;
cout<<x;
return 0;
}
