Cod sursa(job #1878967)

Utilizator WebDesignbyTMGhiorghiu Ioan-Viorel WebDesignbyTM Data 14 februarie 2017 17:15:10
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.37 kb
#include <fstream>
#define md 1999999973
using namespace std;

ifstream fi ("lgput.in");
ofstream fo ("lgput.out");

long long n, p, s = 1, a = 1;

int main ()
{
    fi >> n >> p;
    while(p!=0)
    {
        if (p%2 == 1)
        {
            s = s*n%md;
            --p;
        }
        p/=2;
        n = n*n%md;
    }
    fo << s;
    return 0;
}