Cod sursa(job #1363566)
| Utilizator | Data | 27 februarie 2015 01:49:33 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream is("inversmodular.in");
ofstream os("inversmodular.out");
int a, n;
int Pow(int x, int y);
int main()
{
is >> a >> n;
os << Pow(a, n - 2);
is.close();
os.close();
return 0;
}
int Pow(int x, int y)
{
if ( y == 1 )
return x;
int r = Pow(x, y / 2) % n;
r = ( 1LL * r * r ) % n;
if ( y & 1 )
r = ( 1LL * r * x ) % n;
return r;
}
