Cod sursa(job #1244518)
| Utilizator | Data | 17 octombrie 2014 18:13:33 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
// solutie pt n prim
#include<fstream>
using namespace std;
ifstream fin( "inversmodular.in" );
ofstream fout( "inversmodular.out" );
long long pow_log( int a, int n ) {
long long sol, p;
sol = 1;
p = a;
while ( n > 0 ) {
if ( n % 2 == 1 ) {
sol *= p;
}
p *= a;
n /= 2;
}
return sol;
}
int main() {
int a, n;
fin >> a >> n;
fout << pow_log( a, n ) << "\n";
fin.close();
fout.close();
return 0;
}
