Cod sursa(job #2755112)

Utilizator mihnea20020602Mihnea Gherghel mihnea20020602 Data 26 mai 2021 19:43:11
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.4 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
void ridicare(int n,int p)
{
    int x=1;
    while(p>0)
    {
        if(p%2==1)
        {
            x=x*n;
            p--;
        }
        n=n*n;
        p=p/2;
    }
    fout<<x;
}
int main()
{
    int n,p;
    fin>>n>>p;
    ridicare(n,p);
    return 0;
}