Cod sursa(job #2925975)
Utilizator | Data | 16 octombrie 2022 15:22:21 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
using namespace std;
#define ull unsigned long long
const ull r=1999999973;
int pwr(ull y,ull n,ull p)
{
if(p==0)
return y;
if(p%2==0)
{
return pwr(y%r,n*n%r,p/2);
}
else
{
return pwr(y*n%r,n*n%r,(p-1)/2);
}
}
int main()
{
ifstream cin("lgput.in");
ofstream cout("lgput.out");
ull a,b;
cin >> a >> b;
cout << pwr(1,a,b);
return 0;
}