Cod sursa(job #1311645)
| Utilizator | Data | 8 ianuarie 2015 14:14:59 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int x0,y0;
void euclid_ext(int a,int b)
{
if(b == 0)
{
x0 = 1;
y0 = 0;
}
else
{
euclid_ext(b,a%b);
int x = y0, y = x0 - a/b*y0;
x0 = x , y0 = y;
}
}
int main()
{
int a,n;
f>>a>>n;
euclid_ext(a,n);
while(x0 < 0) x0 += n;
g<<x0<<"\n";
f.close();
g.close();
return 0;
}
