Cod sursa(job #1650842)
Utilizator | Data | 11 martie 2016 20:51:34 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long log_exp(long long n,long long p)
{
long long res=1;
while(p!=0)
{
if(p%2==1)
res=(res*n)%MOD;
p/=2;
n=(n*n)%MOD;
}
return res;
}
int main()
{
long long n,p;
f>>n>>p;
g<<log_exp(n,p);
return 0;
}