Cod sursa(job #1291940)
Utilizator | Data | 13 decembrie 2014 15:17:11 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("lgput.in");
ofstream g ("lgput.out");
const int n_max = 10001;
const int m = 1999999973;
int main()
{
unsigned int i, n, p;
long long a, sol = 1;
f >> n >> p;
a = n;
for (i = 0; (1<<i) <= p; ++ i)
{
if ( ((1<<i) & p) > 0)
sol= (sol * a) % m;
a=(a * a) % m;
}
g << sol;
return 0;
}