Cod sursa(job #2034377)

Utilizator AndreiTurcasTurcas Andrei AndreiTurcas Data 7 octombrie 2017 19:01:20
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream f("lgput.in");
ofstream g("lgput.out");

const int Mod = 1999999973;

long long Exp(int x, int y)
{
    if(y == 1) return x%Mod;
    else if(y % 2 == 0) return Exp((x*x)% Mod, y/2)%Mod;
    else if(y % 2 != 0) return (x * Exp((x*x)% Mod, (y-1)/2))%Mod;
}

int main()
{
    long long n, p;
    f >> n >> p;
    if(!p) g << 1;
    else
    g << Exp(n, p);
}