Cod sursa(job #1510761)
Utilizator | Nemes Alin oopt | Data | 25 octombrie 2015 16:22:40 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <bits/stdc++.h>
#define mod 1999999973
#define ll long long
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long x, p;
void read() {
f>>x>>p;
}
ll put(ll a, ll y) {
if (y == 0) {
return 1;
}
if (y == 1) {
return a;
}
if (y%2 == 0) {
return put((a*a)%mod, y/2)%mod;
}
return (a*(put((a*a)%mod, (y-1)/2)%mod))%mod;
}
int main() {
read();
g<<put(x,p)<<'\n';
f.close(); g.close();
return 0;
}