Cod sursa(job #2086986)

Utilizator rares404AlShaytan - Balasescu Rares rares404 Data 12 decembrie 2017 19:09:40
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 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 ;
    int x = n ;
    int y = 1 ;
    while ( p > 0 )
    {
        if ( p % 2 == 1 )
        {
            y = (y*x) % m ;
        }
        x = (x*x) % m ;
        p /= 2 ;
    }
    out << y ;
    return 0;
}