Cod sursa(job #1650053)
Utilizator | Data | 11 martie 2016 16:18:42 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <iostream>
#include <fstream>
using namespace std;
int exp(long int x, long int n)
{
x=x%1999999973;
if (n==0)return 1;
if (n==1)return x;
if (n%2==0)return exp(x*x,n/2);
else return x*exp(x*x,(n-1)/2);
}
int main()
{
long long int x, n;
ifstream f("lgput.in");
ofstream g("lgput.out");
f>>x>>n;
g<<exp(x,n);
g.close();
f.close();
reutrn 0;
}