Cod sursa(job #1757610)
Utilizator | Craciun Catalin catalincraciun | Data | 15 septembrie 2016 15:15:50 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
#define mod 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long a, b;
long pow(long x, long p) {
if (p == 0)
return 1;
if (p == 1)
return x;
if (p % 2 == 0)
return pow((x*x)%mod, p/2) % mod;
else
return (x * (pow((x*x)%mod, (p-1)/2) % mod)) % mod;
}
int main() {
f>>a>>b;
g<<pow(a, b)<<'\n';
f.close(); g.close();
return 0;
}