Cod sursa(job #1563403)

Utilizator Andrew07Cosmin Alex Andrew07 Data 5 ianuarie 2016 23:38:12
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");

long long fct(long long a,long long A,long long b,long long  c)
{
 if (b<3) return a*a%c;
 else if (b<4) return a*a*a%c;
 else
 {
  a=fct(a,A,b/2,c);
  a=a*a%c;
  if (b%2==1) a=a*A%c;
  return a;
 }
}

int main()
{
 long long a,b,c,A;
 fin>>a>>b;
 a=a%c;
 A=a;
 if (b>1) a=fct(a,A,b,1999999973);
 fout<<a;
 return 0;
}