Cod sursa(job #1651466)

Utilizator leopop29Pop Leonard leopop29 Data 13 martie 2016 13:42:55
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>
#define mod 1999999973

using namespace std;

long long put(int b, int e)
{
    if(!e)
        return 1;
    else if(e&1)
        return (put(b, e-1)*b)%mod;
    else
    {
        long long x = put(b, e/2);
        return (x*x)%mod;
    }
}

int main()
{
    ifstream f("lgput.in");
    ofstream cout("lgput.out");
    int n, p;

    f >> n >> p;

    cout << put(n, p);
    return 0;
}