Cod sursa(job #2900837)
| Utilizator | Data | 12 mai 2022 11:09:37 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("test.in");
ofstream fout ("test.out");
int a,n;
long long RidicareLaPutere (int x, int e){
if (e==0)
return 1;
if (e==1)
return x;
long long rez=1;
while (e){
if (e%2==1)
rez=rez*x%n;
x=x*x%n;
e/=2;
}
return rez;
}
int main()
{
fin >>a>>n;
fout <<RidicareLaPutere (a,n-2);
fin.close ();
fout.close ();
return 0;
}
