Cod sursa(job #1229450)

Utilizator thinkphpAdrian Statescu thinkphp Data 17 septembrie 2014 11:18:16
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator c Status done
Runda Arhiva educationala Marime 0.82 kb
#include <stdio.h>
#define LL long long
#define mod 1999999973
#define FIN "lgput.in"
#define FOUT "lgput.out"

    unsigned int base, expo;
    LL r;

//function prototypes
void read();
void solve();

int main() {

    read();
    solve();
    
   return 0;
};

void read() {

     freopen(FIN, "r", stdin);

     scanf("%d %d", &base, &expo);

     fclose( stdin );
}

LL mypow(base, exp) {

   int i = 0;

   LL sol = 1, base1, exp1;

   base1 = base; 

   exp1 = exp;

   while( (1<<i) <= exp1 ) {

           if (((1<<i) & exp1))  sol = (sol * base1 ) % mod;
  
           base1 = (base1 * base1 ) % mod;

           i++;
   }

   return sol;  
};

void solve() {

    freopen(FOUT, "w", stdout);

    r = mypow(base, expo);

    printf("%lld", r);

    fclose( stdout ); 

}