Cod sursa(job #1486005)
| Utilizator | Data | 13 septembrie 2015 16:05:42 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
long long x;
const int m = 1999999973;
int n;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long PutereLogaritmic(double x, int n)
{
long long p = 1 ;
while (n > 0)
{
if(n%2)
//if (n & 1) // n este impar
{
p *= x;
n-- ;
}
x = x * x ;
n/=2;
// n >>= 1 ; // sau n = n / 2
}
return p ;
}
int main()
{
f>>x>>n;
g<<PutereLogaritmic(x,n)%m<<'\n';
}
