Cod sursa(job #1637929)
Utilizator | Data | 7 martie 2016 20:00:26 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <bits/stdc++.h>
#define MOD 1999999973
#define nmax 10001
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n, p;
int main()
{
fin >> n >> p;
long long a, sol = 1;
a = n;
for(int i = 0; (1<<i) <= p; ++i)
{
if(((1<<i) & p) > 0)
sol = (sol*a) % MOD;
a = (a*a)%MOD;
}
fout << sol;
return 0;
}