Cod sursa(job #1154469)
Utilizator | Sorin Soo sorynsoo | Data | 26 martie 2014 10:37:44 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
ifstream cin("lgput.in");
ofstream cout("lgput.out");
#define mod 1999999973
long long n,p;
long long putere(long long x, long long n)
{
long long p = 1 ;
while (n)
{
if (n %2==1) // n este impar
{
p *= x; p%=mod;
n-- ;
}
x = x * x ; x%=mod;
n/=2;
}
return p%mod ;
}
int main()
{
cin>>n>>p;
cout<<putere(n,p);
}