Cod sursa(job #2194820)

Utilizator calinmackCalin Manoli calinmack Data 14 aprilie 2018 13:45:15
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.in");
#define MOD 1999999973
int put(int x, int p)
{
    int ans=1;
    while(p>0)
    {
        if(p&1) //p%2!=0
            ans=1ll*ans*x%MOD;
        x=1ll*x*x%MOD;
        p=(p>>1); //p=p/2
    }
    return ans;
}
int main()
{
    int n,p;
    in>>n>>p;
    out<<put(n,p);
    return 0;
}