Cod sursa(job #1346167)
| Utilizator | Data | 18 februarie 2015 07:30:47 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
#define ll long long
using namespace std;
ll a, n, x, y;
void euex(ll nr1, ll nr2, ll &x, ll &y)
{
if(!nr2)
{
x=1; y=0;
}
else
{
euex(nr2, nr1%nr2, x, y);
ll x0=x;
x=y;
y=x0-(nr1/nr2)*y;
}
}
int main()
{
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
in>>a>>n;
euex(a, n, x, y);
while(x<0)
x+=n;
out<<x<<"\n";
in.close();
out.close();
return 0;
}
