Cod sursa(job #2668959)
Utilizator | Data | 5 noiembrie 2020 18:56:57 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.26 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int n,m,p,t,prod=1;
int main()
{f>>n>>p;
t=n;
m=1999999973;
while(p)
{
if(p%2==1){prod=(prod*t)%m;p--;}
else{t=t*t%m;p=p/2;}
}g<<prod;
return 0;
}