Cod sursa(job #1604610)
Utilizator | Data | 18 februarie 2016 13:51:20 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include<fstream>
using namespace std;
#define N 1999999973
long hatv(long n,long p)
{
long x=n,y=1;
while(p>0)
{
if(p&1)
{
y*=x;
y=y%N;
}
x*=x;
x=x%N;
p/=2;
}
return y;
}
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
long n,p;
f>>n>>p;
g<<hatv(n,p);
f.close();
g.close();
return 0;
}