Cod sursa(job #1411087)
| Utilizator | Data | 31 martie 2015 13:58:41 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include<fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long putere(int a,int b,int mod){
long long x=1,y=a;
while(b>0){
if(b%2==1){
x=x*y;
if(x>mod)x%=mod;
}
y=(y*y)%mod;
if(y>mod)y%=mod;
b/=2;
}
return x;
}
int main(){
int n,p;
fin>>n>>p;
fout<<(putere(n,p-2,p))<<'\n';
fin.close();
fout.close();
return 0;
}
