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