Cod sursa(job #470791)
| Utilizator | Data | 15 iulie 2010 16:01:30 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std ;
const int MODULO = 100000 ;
long long A , N ;
long long ridicarePutere ( long long A , long long n )
{
long long f = 1 ;
while ( n )
{
if ( n % 2 == 1)
f *= A ;
A *= A ;
A %= N ;
f %= N ;
n /= 2 ;
}
return f ;
}
int main ( )
{
freopen ( "inversmodular.in","r",stdin) ;
freopen ( "inversmodular.out","w",stdout) ;
cin >> A >> N ;
cout << ridicarePutere ( A , N - 2 ) ;
return 0 ;
}