Cod sursa(job #1373558)
Utilizator | Data | 4 martie 2015 19:30:27 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
int long long a, n, l, k=1999999973, p;
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
fin>>n>>p;
a=1;
while(p)
{
if(p%2==0)
{
n*=n;
n%=k;
p/=2;
}
else
{
a*=n;
a%=k;
p--;
}
}
fout<<a;
return 0;
}