Cod sursa(job #1987261)
| Utilizator | Data | 30 mai 2017 02:37:34 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{
int n, p, putere = 1;
const int m = 1999999973;
f >> n >> p;
while(p != 0)
{
if(p % 2 == 1)
{
putere = (putere * n) % m;
p--;
}
n = (n * n) % m;
p = p / 2;
}
g << putere % 1999999973;
return 0;
}
