Cod sursa(job #1937659)

Utilizator nartorrewrew narto Data 24 martie 2017 09:16:02
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <fstream>

#define mod 1999999973

using namespace std;

ifstream f("lgput.in");

ofstream g("lgput.out");

long long  exp_by_squaring(int x,int  n)
{

     if (n == 1)
        return  x%mod ;
    else
    { if (n%2==0)
        return exp_by_squaring((x * x)%mod,  (n / 2)%mod);
    else if (n%2==1)
        return x * exp_by_squaring((x * x)%mod, ((n - 1) / 2)%mod);
    }
}

int main()
{
    int n, m;
    f>>n>>m;
  g<<exp_by_squaring(n,m);
}