Cod sursa(job #1508195)
Utilizator | Data | 22 octombrie 2015 13:20:27 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include<iostream>
#include<fstream>
using namespace std;
#define PRIM 1999999973
//#define PRIM 1000
ifstream in("lgput.in");
ofstream out("lgput.out");
long long sol;
long long exp(long long x, long long n)
{
if(n == 0) return 1;
if(n == 1) return x;
if(n%2 == 1) return (x * exp((x*x)%PRIM, n/2))%PRIM;
return exp((x*x)%PRIM, n/2)%PRIM;
}
int main()
{
long long i,x,n;
in>>x>>n;
sol = exp(x, n);
out<<sol;
return 0;
}