Cod sursa(job #1652072)

Utilizator ManoManole Alexandru Mano Data 14 martie 2016 16:33:47
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include<iostream>
#include<fstream>

using namespace std;

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

const int x =1999999973;

int put(int n,int p)
{
    if(p == 0)
        return 1;
    else if(p == 1)
        return n % x;
        else {
            int aux;
            aux = put(n,p/2);
            aux = (1LL * aux * aux) % x;
            if(p % 2 == 0) return aux;
            else return (1LL * aux * n) % x;
        }
}

int main()
{
    int n , p;
    f >> n >> p;
    put (n,p);
    g << put(n,p);
    f.close();
    return 0;
}