Cod sursa(job #3343534)

Utilizator CristianTudoracheCristian Tudorache CristianTudorache Data 27 februarie 2026 18:20:37
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
    int N, P, ans=1;
    fin>>N>>P;
    while(P>0)
    {
        if(P%2!=0)
        {
            ans=(ans*N)%MOD;
            P--;
        }else{
            N=(N*N)%MOD;
            P/=2;
        }
    }
    fout<<ans;
    return 0;
}