Cod sursa(job #1301864)
| Utilizator | Data | 26 decembrie 2014 14:15:15 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include<vector>
#include<iostream>
#include<fstream>
#define max 1999999973
//#define max 4211
using namespace std;
int main(){
long long p, q;
ifstream in; in.open("lgput.in");
ofstream out; out.open("lgput.out");
in >> p; in >> q;
cout << p << " " << q << endl;
long long result = 1;
while(q > 0) {
if(q % 2){
result = ((result % max) *(p % max)) % max;
q--;
}
p = (((p % max)*(p % max)) % max);
q = q >> 1;
}
out << result;
out.close();
in.close();
return 0;
}
