Cod sursa(job #1250033)

Utilizator Vele_GeorgeVele George Vele_George Data 27 octombrie 2014 19:24:11
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;

int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
int n,p,m,x;

f>>x>>n;
p=1;
while(n!=0){

    if(n % 2 == 1) {
                      p=(p*x) % mod;
                      n--;
                   }
    else {
           x=(x*x) % mod;
           n=n/2;
          }




}
g<<p;


f.close();
g.close();


    return 0;
}