Cod sursa(job #1277237)

Utilizator Robert_EuRobert Pintilii Robert_Eu Data 27 noiembrie 2014 13:40:56
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>
#define MOD 1999999973

using namespace std;

unsigned long long n,x;

inline unsigned long long Ridicare(unsigned long long a,unsigned long long b)
{
    if(b==0) return 1;
    if(b==1)    return a%MOD;
    if(n%2==0)  return Ridicare(a*a%MOD,(b/2)%MOD)%MOD;
    return a%MOD*Ridicare(a*a%MOD,((n-1)/2)%MOD)%MOD;
}

int main()
{
    ifstream fin("lgput.in");
    fin>>n>>x;
    fin.close();

    ofstream fout("lgput.out");
    fout<<Ridicare(n,x)%MOD;
    fout.close();
    return 0;
}