Cod sursa(job #2267907)
Utilizator | Data | 24 octombrie 2018 11:12:39 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream in ("lgput.in");
ofstream out ("lgput.out");
int main()
{
long long base,exp,N=1999999973,t;
in>>base>>exp;
if (exp == 0)
out<<1;
else if (exp == 1)
out<<base % N;
else
{
t = pow(base, exp / 2);
t = (t * t) % N;
if (exp % 2 == 0)
out<<t;
else
out<<((base % N) * t) % N;
}
return 0;
}