Cod sursa(job #2086987)
Utilizator | Data | 12 decembrie 2017 19:10:28 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
using namespace std;
const int m = 1999999973 ;
ifstream in ("lgput.in") ;
ofstream out ("lgput.out") ;
int main()
{
long long n , p , k =1 ;
in >> n >> p ;
long long x = n ;
long long y = 1 ;
while ( p > 0 )
{
if ( p % 2 == 1 )
{
y = (y*x) % m ;
}
x = (x*x) % m ;
p /= 2 ;
}
out << y ;
return 0;
}