Cod sursa(job #2519857)
Utilizator | Data | 8 ianuarie 2020 15:09:50 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long a, b, sol=1;
long long calculate() {
f>>a>>b;
if(b==0)
return 1;
if(b==1)
return a;
while(b) {
if(b%2==1) {
sol=(sol*a)%MOD;
b--;
}
a*=a%MOD;
b/=2;
}
return sol;
}
int main() {
g<<calculate();
return 0;
}