Cod sursa(job #1522031)
Utilizator | Data | 11 noiembrie 2015 08:44:57 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.62 kb |
#include <fstream>
#define mod 1999999973
using namespace std;
long long expRap(long long a, long long b)
{
if (b == 0) return 1;
int aux = 1;
while (b > 1)
{
if (b % 2 == 0)
{
a = (a * a) % mod;
b /= 2;
}
else
{
aux = (aux * a) % mod;
b--;
}
}
return (a * aux) % mod;
};
long long n, p;
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
f >> n >> p;
long long rez = expRap(n, p);
if (rez > 0) g << rez;
else g << rez + mod;
return 0;
}