Cod sursa(job #2170670)

Utilizator bogdan31Bogdan Simion bogdan31 Data 15 martie 2018 09:18:38
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <fstream>
#define mod 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");

long long n,x,copie;
void fct()
{
    if(n>0)
    {
    if(n%2==0)
    {
        x=x*x;
        x%=mod;
        n/=2;
        fct();
    }
    else
    {
        x=x*copie;
        x%=mod;
        n--;
        fct();
    }
    }
}
int main()
{
    f>>x>>n;
    copie=x;
    fct();
    g<<x;
    return 0;
}