Cod sursa(job #1597196)
Utilizator | Data | 11 februarie 2016 19:45:58 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | please_d0_not_enter | Marime | 0.4 kb |
#include <iostream>
#include <fstream>
using namespace std;
int putere(int x,int y)
{int p;
p=1;
while(y>0)
{if(y%2==0)
{x=x*x;
y=y/2;
}
else
{p=p*x;
y--;
}}
return p;
}
int main()
{
long n,p;
fstream f("fisier.in",ios::in);
fstream g("lgput.out",ios::out);
f>>n>>p;
g<<putere(n,p)%1999999973;
g.close();
f.close();
}