Cod sursa(job #1999805)

Utilizator vladschillerVlad Radu Schiller vladschiller Data 12 iulie 2017 10:10:34
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <iostream>
#include <fstream>
#define rest 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
unsigned long long int n,p,x=1;
void putere()
{
    while(p)
    {
        if(p%2==1)
        {
            x=(x*n)%rest;
            p--;
        }
        else
        {
            n=(n*n)%rest;
            p/=2;
        }
    }
}
int main()
{
    f>>n>>p;
    putere();
    g<<x;
    return 0;
}