Cod sursa(job #1490441)
Utilizator | Data | 23 septembrie 2015 16:14:17 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int bin_exp(int n, int p){
long long x = 1;
while(p){
if(p&1){
x = (1LL*x*n) % 1999999973;
p--;
}
p/=2;
n= (1LL*n*n) % 1999999973;
}
return x;
};
int N,P;
int main(){
fin >> N >> P;
fout << bin_exp(N,P);
return 0;
}