Cod sursa(job #2060468)
Utilizator | Data | 8 noiembrie 2017 12:03:07 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include<fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int n,p,sol,w;
int main()
{
f >> n>>p;
sol=1;
w=1999999973;
while(p>0)
{
if(p%2==1)
sol=(sol*n) % w;
n=n*n;
p=p/2;
}
g << sol;
return 0;
}