Cod sursa(job #2365155)
Utilizator | Data | 4 martie 2019 12:16:19 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
#define const 11999999973
using namespace std;
int main()
{ unsigned long long n,p,nr = 1;
ifstream fin("modulo.in");
ofstream fout("modulo.out");
fin>>n>>p;
n%=const;
while (p>0)
{
if (p%2==1)
{
nr=(nr*n)%const;
p--;
}
else
{
n=(n*n)%const;
p=p/2;
}
}
fout<<nr;
return 0;
}