Cod sursa(job #1397074)
Utilizator | Data | 23 martie 2015 11:33:35 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
#define M 1999999973
#define LL long long
using namespace std;
LL putere(LL n,LL p)
{
LL pt=1;
while(p>0)
{
if(p & 1)
{
pt=(pt % M * n % M)%M;
p--;
}
n=(n%M * n%M) % M;
p>>=1;
}
return pt;
}
int main()
{
LL n,p;
ifstream f("lgput.in");
ofstream g("lgput.out");
f>>n>>p;
g<<putere(n,p);
f.close();
g.close();
}