Cod sursa(job #1923011)
Utilizator | Data | 10 martie 2017 20:15:34 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
#define mod 1999999973
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
int main (){
int x,n;
fin >> x >> n;
int y = 1;
while (n > 1){
if (n%2==0){
x = 1LL*x*x%mod;
n = n/2;
}
else {
y = 1LL * y * x%mod;
x = 1LL * x * x%mod;
n = (n-1)/2;
}
}
int rasp = 1LL * x * y%mod;
fout << rasp;
}