Cod sursa(job #1734263)

Utilizator codebreaker24Tivadar Ionut codebreaker24 Data 26 iulie 2016 22:03:36
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <iostream>
#include <fstream>
using namespace std;
const int m = 1999999973;

long long expLogTime(long long  x, long long n);

int main()
{
    long long x, y;


    ifstream fin ("lgput.in");
    ofstream fout ("lgput.out");


    fin >> x >> y;
    fout << expLogTime(x,y) << '\n';
    fin.close();
    fout.close();

    return 0;
}


long long expLogTime(long long x, long long n)
{
    long long aux = 1;
    if (n==0)
        return 1;
    if(n== 1)
        return (x%m);
    while(n > 1)
    {
        if(n%2)
        {
            aux = (aux*x) %m;
            x = (x*x) %m;
            n = (n-1)/2;
        }
        else
        {
            x =(x*x)%m;
            n = n/2;

        }

    }

    return (x *aux)%m;



}