Cod sursa(job #1918582)
Utilizator | Data | 9 martie 2017 16:03:30 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long int mod = 1999999973;
long long int n, p, a = 1;
void putere()
{
while(p != 1)
{
if(p % 2 == 1)
{
a *= n % mod;
p--;
}
else
{
n = (n *n) % mod;
p/=2;
}
}
fout << (a * n) % mod;
}
int main()
{
fin >> n >> p;
putere();
return 0;
}