Cod sursa(job #2397833)
| Utilizator | Data | 4 aprilie 2019 19:58:01 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int f(int n,int p)
{if(n==0)
{
return 0;
}
if(p==1)
{
return 2;
}
if(p==0)
{
return 1;
}
if(p%2==0)
{
return f(n%1999999973,p/2)*f(n%1999999973,p/2);
}
else
{
return f(n%1999999973,p/2)*f(n%1999999973,(p/2)+1);
}
}
int main()
{int n,p;
fin>>n>>p;
fout<<f(n,p);
}
