Cod sursa(job #2544026)
| Utilizator | Data | 11 februarie 2020 18:28:55 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
using namespace std;
#define MOD 1999999973
long unsigned power (long unsigned n, long unsigned p)
{
if(p == 0)
return 1;
if(p == 1)
return n%MOD;
if(p%2 == 0)
return (power(n,p/2)%MOD*power(n,p/2)%MOD)%MOD;
return (power(n,p/2)%MOD*power(n,p/2)%MOD* n%MOD) % MOD;
}
int main()
{
long unsigned n,p;
fin>>n>>p;
fout<<power(n,p);
return 0;
}
//1284616625
