Cod sursa(job #1040955)
Utilizator | Data | 25 noiembrie 2013 11:33:08 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int mod = 1999999973;
long long n, p, sol = 1;
int main()
{
fin>>n>>p;
for(int i=0; (1<<i) <= p; i++)
{
if((1<<i) & p)
sol = (sol * n) % mod;
n = (n * n) % mod;
}
fout<<sol;
return 0;
}