Cod sursa(job #2569382)
Utilizator | Data | 4 martie 2020 11:58:40 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
ifstream cin("inversmodular.in");
ofstream cout("inversmodular.out");
int x , N;
typedef long long ll;
int power(int x, int p)
{
ll ans = 1;
while(p)
{
if( p % 2 )
ans = (1LL* ans * x) % N;
x = (1LL * x * x) % N;
p/=2;
}
return ans;
}
int main() {
cin >> x >> N;
cout << power(x, N - 2);
return 0;
}