Cod sursa(job #1972804)
Utilizator | Data | 23 aprilie 2017 18:58:26 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.33 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int n,p,prod=1,t;
int main()
{
f>>n>>p;
t=n;
while(p!=1)
{
if(p%2==1){prod=(prod*t)%1999999973;p--;}
else {t=(t%1999999973*t%1999999973)%1999999973;p=p/2;}
}
g<<(prod*t)%1999999973;
return 0;
}