Cod sursa(job #1498138)
| Utilizator | Data | 7 octombrie 2015 23:30:28 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int n,p;
long long PutereLogaritmic(long long x, int n)
{
long long p = 1 ;
while (n > 0)
{
if (n & 1) // n este impar
{
p *= x;
p=p%100003;
n-- ;
}
x = x * x ;
x=x%100003;
n >>= 1 ; // sau n = n / 2
}
return p;
}
int main()
{
f>>n>>p;
g<<PutereLogaritmic(n,p);
return 0;
}
