Cod sursa(job #2397830)
| Utilizator | Data | 4 aprilie 2019 19:56:19 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.39 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,p/2)*f(n,p/2);
}
else
{
return f(n,p/2)*f(n,(p/2)+1);
}
}
int main()
{int n,p;
fin>>n>>p;
fout<<f(n,p);
}
