Mai intai trebuie sa te autentifici.
Cod sursa(job #1522028)
| Utilizator | Data | 11 noiembrie 2015 08:42:01 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 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 % mod;
b /= 2;
}
else
{
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;
g << expRap(n, p);
return 0;
}
