Cod sursa(job #1806317)
Utilizator | Data | 15 noiembrie 2016 09:26:43 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
const int mod = 1999999973;
int n, p;
long long sol = 1, a;
fin >> n >> p;
while(p)
{
if(p % 2 == 0)
{
p /= 2;
n = (n * n) % mod;
}
else
{
p--;
sol = ( sol * n ) % mod;
}
}
fout << sol;
return 0;
}