Cod sursa(job #1649886)
Utilizator | Data | 11 martie 2016 15:34:30 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
#define mod 1999999973
using namespace std;
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
int n,p;
long long x=1LL;
f>>n>>p;
while (p)
{
if (!(p%2))
{
p/=2;
n=(n*n)%mod;
}
else
{
p--;
x=(x*n)%mod;
}
}
g<<x<<'\n';
f.close();
g.close();
return 0;
}