Cod sursa(job #2705498)

Utilizator PatruMihaiPatru Mihai PatruMihai Data 12 februarie 2021 17:42:32
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.36 kb
#include <bits/stdc++.h>

using namespace std;

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

int main()
{
    long long int n, p;
    fin >> n >> p;

    long long ans = 1;

    while(p > 0)
    {
        if(p % 2 == 0)
        {
            ans *= n;
        }
        n = n * n;
        p /= 2;
    }
    fout << ans;
    return 0;
}