Cod sursa(job #2467800)
Utilizator | Data | 5 octombrie 2019 08:23:14 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <bits/stdc++.h>
#define Mod 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int LogP(int a, int n)
{
int p = 1;
while(n > 0)
{
if(n % 2 == 1)
p = 1LL * p * a % Mod;
n /= 2;
a = 1LL * a * a % Mod;
}
return p;
}
int main()
{
int a, n;
fin >> a >> n;
fout << LogP(a, n);
return 0;
}