Cod sursa(job #394661)

Utilizator swxxIoo Andrei Rares swxx Data 11 februarie 2010 12:24:25
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <fstream>
#include <stdlib.h>
#include <math.h>



    long n,p;
using namespace std;

void citire()
{
     ifstream f("lgput.in");
     f>>n>>p;
     f.close();
     }

int calcul(int n,int p)
{
    if (p==0) return 1;
    else
    if (p%2==0) 
      return (calcul(n,p/2)%1999999973)<<1;
      else  
        return n*calcul(n,p-1)%1999999973;
        }  
int main()
{

      citire();
      ofstream g("lgput.out");
      n=n%1999999973;
      g<<calcul(n,p);
      g.close();
    return 0;
}