Cod sursa(job #1980045)

Utilizator alexandrasirbuAlexandra alexandrasirbu Data 11 mai 2017 23:55:43
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.31 kb
#include <bits/stdc++.h>
using namespace std;

ifstream ff("lgput.in");
ofstream f("lgput.out");
int main() {
    long long n,p,x,max=1999999973,s;
    ff>>n>>p;
    x = n; s = 1;
    while (p){
    if (p%2==1) {
    s *=x ; s%=max;
    }
    x = (x*x)%max;
    p = p/2;
    }
    f<<s;
    return 0;
}