Cod sursa(job #2155033)
Utilizator | Data | 7 martie 2018 15:42:51 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;
ifstream f ("lgput.in");
ofstream g ("lgput.out");
long long n,p,nr = 1;
int main()
{
f >> n >> p;
while(p)
{
if(p % 2 == 0)
n = (n * n) % mod , p /= 2;
else nr = (nr * n) % mod, p--;
}
g << nr;
return 0;
}