Cod sursa(job #2064778)
Utilizator | Data | 12 noiembrie 2017 19:52:57 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
using namespace std;
ifstream fis1("lgput.in");
ofstream fis2("lgput.out");
int main()
{
long long n,p,sol,w;
fis1>>n>>p;
sol=1;
w=1999999973;
while(p>0)
{
if(p%2==1)
sol=(sol*n)%w;
n=(n*n)%w;
p=p/2;
}
fis2<<sol;
fis1.close();
fis2.close();
return 0;
}