Mai intai trebuie sa te autentifici.
Cod sursa(job #2985857)
Utilizator | Data | 27 februarie 2023 11:52:36 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-32 | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
long long N,P;
const int m=1999999973;
long long e(long long N , long long P)
{
if(P== 0)
return 1;
long long x = e(N , P / 2)%m;
if(P % 2 == 1)
return N*x*x;
return x*x;
}
int main()
{
fin>>N>>P;
fout<<e(N,P);
}