Cod sursa(job #1453986)
| Utilizator | Data | 25 iunie 2015 11:13:54 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
int expo(long int a, long int b)
{ long int p ;
if ( b == 0 )
return 1 ;
else if ( b % 2 == 1 )
return a * expo(a, b - 1) % 1999999973 ;
else
p = expo (a, b / 2) % 1999999973 ;
return p * p % 1999999973 ;
}
int main ()
{
long int N , P;
fin>>N>>P;
long int exp = expo (N,P) ;
fout << exp;
return 0;
}
