Cod sursa(job #2277982)
Utilizator | Data | 7 noiembrie 2018 09:48:09 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.28 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int n,p,a;
int main()
{
f>>n;
f>>p;
a=n;
while(p>1)
{
if(p%2==0) {a=(a*a)%1999999973;p=p/2;}
else {a=(a*n)%1999999973;p--;}
}
g<<a;
return 0;
}