Cod sursa(job #1346278)
Utilizator | Data | 18 februarie 2015 09:42:54 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include<fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
const long long REST = 1999999973;
int putere (int a, int b)
{
long long aux = a, ret = 1, i;
for(i = 1; i <= b; i = i<<1)
{
if(i & b) ret = ret * aux;
aux = aux * aux;
ret %= REST;
aux %= REST;
}
return ret;
}
int main()
{
long long n,p;
f >> n >> p;
g << putere(n,p);
return 0;
}