Cod sursa(job #2279824)
Utilizator | Data | 10 noiembrie 2018 08:00:34 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
ifstream f ("lgput.in");
ofstream g ("lgput.out");
int k=1999999973;
long long int exp(long long int x,long long int y)
{
x%=k;
if(y==0)
{
return 1;
}
if(y%2)
{
return x*exp(x*x,(y-1)/2);
}
return exp( x*x,y/2);
}
int main()
{
long long int n,p;
f>>n>>p;
g<<exp(n,p);
}