Cod sursa(job #719932)
Utilizator | Data | 22 martie 2012 10:43:35 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
#include <string.h>
using namespace std;
const int n_max = 10001;
const int m = 1999999973;
int main()
{
unsigned int i, n, p;
long long a, sol = 1;
ifstream f("lgput.in");
ofstream h("lgput.out");
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;
}
h<<sol;
return 0;
}