Cod sursa(job #1487859)

Utilizator Bijoux12Andreea Gae Bijoux12 Data 17 septembrie 2015 15:47:53
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <iostream>
#include <fstream>

using namespace std;
long long N,P;
long long putere( long long x, long long p)
{
    long long m=1999999973;
    if (p==0)
        return 1;
    long long aux=putere (x,p/2);
    if (p%2==0)
        return (aux*aux)%m;
    return (aux*aux%m*x)%m;
}
int main()
{

    ifstream f("lgput.in");
    ofstream g("lgput.out");
    f>>N>>P;
    g<<putere(N,P);
    return 0;
}