Cod sursa(job #1916823)
Utilizator | Data | 9 martie 2017 10:27:50 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <stdio.h>
#define m 1999999973
using namespace std;
FILE *f,*g;
int main()
{
f=fopen("lgput.in","r");
g=fopen("lgput.out","w");
long long n,p,x;
fscanf(f,"%lld %lld",&n,&p);
x=1;
while(p)
{
if(p%2==1)
{
x=(x*n)%m;
}
n=(n*n)%m;
p/=2;
}
fprintf(g,"%lld",x);
return 0;
}