Cod sursa(job #1880998)
Utilizator | Data | 16 februarie 2017 08:40:39 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <stdio.h>
#define y 1999999973
using namespace std;
FILE *f,*g;
int main()
{
long long n,x,rez=1,p;
f=fopen("lgput.in","r");
g=fopen("lgput.out","w");
fscanf(f,"%lld %lld",&x,&n);
while(n!=0)
{
if(n%2!=0)
{
rez*=x;
n--;
}
x*=x;
n/=2;
}
fprintf(g,"%lld",rez);
cout<<rez;
fclose(f);
fclose(g);
return 0;
}