Cod sursa(job #3225181)
Utilizator | Alexandru Haidet Hadef | Data | 16 aprilie 2024 23:30:33 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long recursiv(long long x,int n)
{
if(n ==0)
return 1;
long long x_pat = recursiv(x,n/2);
x_pat = (x_pat * x_pat)%mod;
if(n%2==0)
return x_pat;
else
return (x*x_pat)%mod;
}
int main()
{
long long P=1;
long long baza,exp;
fin>>baza>>exp;
fout<<recursiv(baza,exp);
return 0;
}