Cod sursa(job #2562314)
Utilizator | Data | 29 februarie 2020 13:27:54 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int P(int a,int n,int C)
{
int p = 1;
while(n != 0)
{
if(n % 2 == 1)
p = 1LL * p * a % C;
a = 1LL * a * a % C;
n /= 2;
}
return p;
}
int main()
{
int n,p;
fin >> n >> p;
fout << P(n,p,1999999973) << "\n";
return 0;
}