Cod sursa(job #889730)
| Utilizator | Data | 24 februarie 2013 17:56:34 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
const long long int P=1999999973;
long long int exponentiere(int x,int n){
if(n==1)
return x%P;
else
if(n%2==1)
return ( (x%P)* (exponentiere( (x%P)*(x%P)%P,(n-1)/2)) )%P;
else
return exponentiere ( ((x%P)*(x%P)),n/2);
}
int n,p;
int main(){
f>>p>>n;
g<<exponentiere(p,n);
return 0;
}
