Cod sursa(job #1033032)

Utilizator TheNechizFMI Razvan Birisan TheNechiz Data 16 noiembrie 2013 13:08:02
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
# include <fstream>
# define ll long long
# define MOD 1999999973
using namespace std;

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

ll N,P;

int main()
{
    fin >> N >> P;

    ll s=1,exp=N;
    for(;P;P>>=1){
        if( P&1 )
            s = (s*exp) % MOD;
    exp = (exp*exp) % MOD;
    }

    fout << s;

    fin.close();
    fout.close();
    return 0;
}