Cod sursa(job #1714592)
| Utilizator | Data | 8 iunie 2016 19:35:44 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int a,n;
void gcd(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1;
y=0;
return;
}
int x1,y1;
gcd(b,a%b,x1,y1);
x=y1;
y=x1-y1*(a/b);
}
int main()
{
int x,y;
f>>a>>n;
gcd(a,n,x,y);
if(x<0) x=n+x%n;
g<<x;
f.close();
g.close();
return 0;
}
