Cod sursa(job #2892360)
Utilizator | Data | 21 aprilie 2022 18:48:09 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#include <cmath>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int main()
{
int n,p,x,r=1;
in>>n>>p;
x=1999999973;
while(p!=1)
{
if(p%2==0)
{
n=(n*n)%x;
p=p/2;
}
else
{
r=(r*r)%x;
p--;
}
}
n=(n*r)%x;
out<<n%x;
return 0;
}