Pagini recente » Cod sursa (job #1854787) | Cod sursa (job #2808090) | Cod sursa (job #1409664) | Cod sursa (job #303460) | Cod sursa (job #1363566)
#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;
}