Cod sursa(job #1188221)
Utilizator | Data | 19 mai 2014 07:54:41 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
const int mod=1999999973;
int n, p, x;
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{
f>>n>>p;
x=n;
while (p!=1) {
if (p%2==0) {
x=(x*x)%mod;
p/=2;
}
else {
x=(x*x)%mod;
x=(x*n)%mod;
p/=2;
}
}
g<<x;
return 0;
}