Cod sursa(job #2918866)
Utilizator | Data | 13 august 2022 16:02:49 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long power(long long a, long long b, long long c)
{
long long p = 1LL;
while(b > 0)
{
if(b % 2 == 1)
p = ((p % c) * (a % c)) % c;
a = ((a % c) * (a % c)) % c;
b >>= 1;
}
return p;
}
int main()
{
long long a, b;
fin >> a >> b;
const int c = 1999999973;
fout << power(a, b, c);
return 0;
}