Cod sursa(job #2033273)
Utilizator | Dobos Paul Dobos | Data | 6 octombrie 2017 15:51:59 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.59 kb |
#include <stdio.h>
#include <stdlib.h>
typedef long long var;
const long MOD = 1999999973;
int Lgpower(var x,var n,var y){
if(n <= 1)
return y;
x = Lgpower(x,n/2,y);
x = (x * x) % MOD;
if(n % 2 == 1)
x = (x * y) % MOD;
return x;
}
int main()
{
var n,x;
FILE *fin;
FILE *fout;
fin = fopen("lgput.in","r");
fout = fopen("lgput.out","w");
fscanf(fin , "%lld %lld", &x, &n);
var solution = Lgpower(x,n,x);
fprintf(fout,"%lld", solution);
fclose(fin);
fclose(fout);
return 0;
}