Cod sursa(job #1509811)
| Utilizator | Data | 24 octombrie 2015 12:27:32 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
using namespace std;
ifstream in ("lgput.in");
ofstream out ("lgput.out");
int main()
{
int P ;
long long N, n, r=1;
in>>N>>P;
while( P!=1)
{
if( P%2==0)
{
N=(N*N)%1999999973;
P=P/2;
}
else
{
P=P-1;
r=(r*N)%1999999973;
}
}
n=(N*r)%1999999973;
out<<n;
return 0;
}
