Cod sursa(job #3002900)

Utilizator TanasucaGeorgeAlexandruTanasucaGeorgeAlexandru TanasucaGeorgeAlexandru Data 15 martie 2023 12:21:38
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.35 kb
#include <bits/stdc++.h>
using namespace std;

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

int Exp(int x,int p){
    int a=1;
    while(p>0){
        if(p%2==1){
            a*=x;
        }
        x*=x;
        p/=2;
    }
    return a;
}

int main()
{
    int x,p;
    fin >> x >> p;
    fout << Exp(x,p);
    return 0;
}