Cod sursa(job #1649862)
Utilizator | Data | 11 martie 2016 15:26:47 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 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*=n;
x%=mod;
}
}
g<<x<<'\n';
f.close();
g.close();
return 0;
}