Cod sursa(job #1021093)
| Utilizator | Data | 3 noiembrie 2013 11:00:24 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
#define nr 1999999973
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
long long n,p,rez=1;
void read()
{
in>>n>>p;
}
void solve()
{
for(short int i=0;(1<<i)<=p;i++)
{
if( ((1<<i) & p) != 0 )
{
rez = ( rez * n ) % nr;
}
n = (n * n) % nr;
}
}
void write()
{
out<<rez;
}
int main()
{
read();
solve();
write();
}
