Cod sursa(job #1490414)
Utilizator | Data | 23 septembrie 2015 14:57:09 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
#define ll long long
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
ll n,p;
ll vlad(ll p)
{
if(p==1)
return n;
ll x=vlad(p/2);
if(p%2==0)
return x*x%1999999973;
else
return x*x%1999999973*n%1999999973;
}
int main()
{
f>>n>>p;
g<<vlad(p)<<' ';
return 0;
}