Cod sursa(job #3227543)

Utilizator TurcuDavid1Turcu David-Mihai TurcuDavid1 Data 1 mai 2024 19:37:25
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.47 kb
#include <stdio.h>

#define NUMBER_MAX 1999999973

int main() {
  freopen("lgput.in","r",stdin);
  freopen("lgput.out","w",stdout);
  long long numar, putere;
  scanf("%lld%lld", &numar, &putere);
  numar %= NUMBER_MAX;
  long long result = 1;
  while (putere) {
    if (putere % 2 == 1) {
      result = result * numar % NUMBER_MAX;
      putere -= 1;
    } else {
      numar = numar * numar % NUMBER_MAX;
      putere /= 2;
    }
  }
  printf("%lld\n", result);
  return 0;
}