Cod sursa(job #1869731)

Utilizator petru.ciocirlanPetru Ciocirlan petru.ciocirlan Data 6 februarie 2017 09:30:42
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
/// a = a/b * b * a%b
/// a%b = a - a/b * b
#include <bits/stdc++.h>
/// #define Mod 1999999973
#define LL long long
using namespace std;
LL b, n, p, r;
const int Mod = 1999999973;

ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{
    f>>n>>p;
    for(b = n, r = 1; p; p>>=1)
    {
        if(p&1) r = (r*b)%Mod;
        b = (b*b)%Mod;
    }
    g<<r;
    return 0;
}