Cod sursa(job #2468158)
Utilizator | Data | 5 octombrie 2019 13:12:01 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
int LogP(int a, int n)
{
int rez = 1;
while (n > 0)
{
if (n % 2 == 1)
rez = 1LL * rez * a % 1999999973;
n /= 2;
a = 1LL * a * a % 1999999973;
}
return rez;
}
int main()
{
int n, p;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
fin >> n >> p;
fout << LogP(n, p) << "\n";
fout.close();
return 0;
}