Cod sursa(job #2385193)
Utilizator | Data | 21 martie 2019 18:23:18 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
#include <string.h>
using namespace std;
ifstream in ("lgput.in");
ofstream out ("lgput.out");
int n,p,x,y,pow=1;
int main()
{
in >> n >> p;
x=n;
while(pow<p)
{
y=x;
x=x*x;
pow=pow*2;
x=x%1999999973;
}
if(pow==p)
{
out << x;
return 0;
}
x=x/y;
pow=pow/2;
while(pow<=p)
{
x=x*n;
x=x%1999999973;
pow++;
}
out << x;
return 0;
}