Cod sursa(job #1525254)

Utilizator HorridSaracin Mihnea Horrid Data 14 noiembrie 2015 21:34:31
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator c Status done
Runda Arhiva educationala Marime 0.55 kb
#include <stdio.h>
#include <stdlib.h>
const long long m=1999999973;
FILE *f,*g;


long long   exp(long long x,long long i)
{
    if(i==0)    return  1;
   else if (i==1)       return x;
         if(i%2==0)    return  exp(x*x,i/2);
            else if(i%2==1)   return x*exp(x*x,(i-1)/2);



}

int main()
{
   long long n,p,z;


    f=fopen("lgput.in","r");
    g=fopen("lgput.out","w");
    fscanf(f,"%lld",&n);
      fscanf(f,"%lld",&p);
      z=exp(n,p);
   fprintf(g,"%lld",z%m);
    fclose(f);
    fclose(g);

    return 0;
}