Cod sursa(job #1782053)

Utilizator LizaSzabo Liza Liza Data 17 octombrie 2016 19:02:36
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.32 kb
#include <fstream>
using namespace std;

ifstream fin("lgput.in");
ofstream fout("lgput.out");


int main()
{
    int N,P,Sol = 1;

    fin >> N >> P;

    while(P)
      {
        if(P%2 == 1)
          Sol = Sol * N;
        N = N * N;
        P = P / 2;
      }

    fout<<Sol<<"\n";
    return 0;
}