Cod sursa(job #1166696)

Utilizator muresan_bogdanMuresan Bogdan muresan_bogdan Data 3 aprilie 2014 19:15:26
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include<iostream>
#include<fstream>
using namespace std;

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

int n, p, rez;

int main() {
    fin >> n >> p;
    rez = 1;
    while(p) {
        if(p%2) {
            rez *= n;
            p--;
        }
        n *= n;
        p /= 2;
    }
    fout << rez << '\n';
    fin.close();
    fout.close();
    return 0;
}