Cod sursa(job #1417119)
Utilizator | Data | 9 aprilie 2015 17:13:37 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
#define MOD 1999999973
using namespace std;
long putere(long x, long y)
{
long p = 1;
while (y > 0)
{
if (y & 1)
{
p *= x;
y-- ;
}
x = x * x ;
y >>= 1 ;
}
return p ;
}
int main()
{
int n,p;
ifstream f("lgput.in");
ofstream g("lgput.out");
f>>n>>p;
g<<putere(n,p)%MOD;
return 0;
}