Cod sursa(job #1223660)
Utilizator | Data | 28 august 2014 15:41:08 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
using namespace std;
#define MOD 1999999973
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long n, p, sol = 1;
int main() {
fin >> n >> p;
while ( p > 0 ) {
if ( p % 2 == 1 ) {
sol *= n;
sol %= MOD;
}
p /= 2;
n *= n;
n %= MOD;
}
fout << sol % MOD << '\n';
fin.close();
fout.close();
return 0;
}