Cod sursa(job #2030222)
| Utilizator | Data | 1 octombrie 2017 12:31:04 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <iostream>
#define N 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long n, p;
long long ridicare(long long x, long long z)
{
if (z == 0)
return 1;
if(z == 1)
return n%N;
int y = 1;
while (z > 1) {
if (z % 2 == 0)
{
x = (x * x) % N;
z = z / 2;
}
else
{
y = (y * x) % N;
x = (x * x) % N;
z = (z - 1) / 2;
}
}
return (x * y) % N;
}
int main()
{
fin>>n>>p;
fout<<ridicare(n,p);
return 0;
}
