Cod sursa(job #2245338)
| Utilizator | Data | 25 septembrie 2018 09:27:03 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
#define llu long long unsigned
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const llu r=1999999973;
llu lgex(llu x,llu p)
{
if(p==0)return 1;
if(p==1)return x%r;
if(p%2==0)return lgex(x*x%r,p/2);
if(p%2==1)return x*lgex(x*x%r,(p-1)/2)%r;
}
int main()
{
llu a,put;
fin>>a>>put;
fout<<lgex(a,put);
return 0;
}
