Cod sursa(job #2358080)

Utilizator DenisPetreCsRekkles DenisPetre Data 27 februarie 2019 21:19:17
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.59 kb
#include <iostream>
#include <fstream>
#define Mod 1999999973

using namespace std;

ifstream f("lgput.in");
ofstream g("lgput.out");

long long x,y,sol=1;

long long putere(int x,int y)
{
    if(y==1)
    {
        return x;
    }
    if(y==0)
    {
        return 1;
    }
    else
    {


        if(y%2==0)
        {
            sol=putere(x,y/2);
            sol=sol*sol%Mod;
        }
        else
        {
            sol=(putere(x,y-1));
            sol=(sol*x)%Mod;

        }
    }
}
int main()
{
    f>>x>>y;
    g<<putere(x,y)%Mod;
    return 0;
}