Cod sursa(job #1469310)
| Utilizator | Data | 8 august 2015 00:14:18 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
#define fin "lgput.in"
#define fou "lgput.out"
#define Modulo 1999999973;
#define MOD 1999999973
using namespace std;
ifstream t1(fin);
ofstream t2(fou);
long long sol,p,n;
long long exp(long long x,long long n)
{
if(n==0) return 1;
else
{
if(n%2==0) return exp((x*x) % MOD ,n / 2 );
if(n%2==1) return ( exp(x,n-1)* x)%MOD;
}
}
int main()
{
t1>>n>>p;
sol=exp(n,p);
t2<<sol<<'\n';
t1.close();
t2.close();
return 0;
}
