Cod sursa(job #1584318)
Utilizator | Data | 29 ianuarie 2016 22:17:24 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;
ifstream f ("lgput.in");
ofstream g ("lgput.out");
long long p,n,numar = 1;
int main()
{
f >> n >> p;
while(p > 0){
if((p & 1))
{
numar = (numar * n) % mod;
p--;
}
else
{
n = (n * n) % mod;
p = (p >> 1);
}
}
g << numar;
return 0;
}