Cod sursa(job #1873559)
Utilizator | Data | 9 februarie 2017 10:54:14 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n,p,i,x,k;
bool v[35];
int main()
{
fin>>n>>p;
while (p!=0)
{
k++;
v[k]=p%2;
p/=2;
}
x=1;
for (i=k;i>=1;i--)
{
x=(1ll*x*x)%1999999973;
if (v[i]==1)
x=(1ll*x*n)%1999999973;
}
fout<<x;
return 0;
}