Cod sursa(job #1649088)

Utilizator hackerliAndrei Ion hackerli Data 11 martie 2016 12:30:58
Problema Ridicare la putere in timp logaritmic Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long putere(long long x, long long y)
{
    if(y==1)
    {
        return (x%mod);
    }
    else
    {
        long long a=putere(x, y/2);
        if(y%2==0)
        {
            return (a*a)%mod;
        }
        else
        {
            return (a*a*x)%mod;
        }
    }
}
int main()
{
    int n, m;
    fin>>n>>m;
    fout<<putere(n, m);
    fin.close();
    fout.close();
    return 0;
}