Cod sursa(job #3331477)
| Utilizator | Data | 28 decembrie 2025 14:38:59 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <fstream>
#include <iostream>
using namespace std;
#define N 1000000007
ifstream fIn("lgput.in");
ofstream fOut("lgput.out");
long int expo(long int b, long int exp1)
{
if (exp1 == 0)
return 1;
if (exp1 == 1)
return b % N;
long int t = expo(b, exp1 / 2);
t = (t * t) % N;
if (exp1 % 2 == 0)
return t;
else
return ((b % N) * t) % N;
}
int main()
{
long int n,p;
fIn>>n>>p;
fOut<<expo(n,p);
return 0;
}