Cod sursa(job #1376218)
Utilizator | Data | 5 martie 2015 16:36:34 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include<fstream>
using namespace std;
ifstream f("lgput.in"); ofstream g("lgput.out");
const int M=1999999973;
long long x;
long long p,n;
void put(int k)
{
if(k)
{ if(k%2==1)
{ x=((x%M)*(n%M))%M;
put(k-1);
}
else
{ n=((n%M)*(n%M))%M;
put(k/2);
}
}
}
int main()
{ f>>n>>p;
x=1;
put(p);
g<<x<<"\n"; g.close(); return 0 ;
}