Cod sursa(job #1984681)

Utilizator ImbuzanRaduImbuzan Radu ImbuzanRadu Data 25 mai 2017 17:50:01
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int putere(int a,int b)
{
    if(b==0)return 1;
    else
    if(b%2==0)
        return (putere(a,b/2)%1999999973)*(putere(a,b/2)%1999999973);
    else  return (putere(a,b/2)%1999999973)*(putere(a,b/2)%1999999973)*a;
}

int main()
{
    int n,p;
    f>>n>>p;
    g<<putere(n,p)%1999999973;
    return 0;
}