Cod sursa(job #1897668)
Utilizator | Data | 1 martie 2017 17:05:17 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long log(int x, int p)
{
long long sol = 1;
for(int i=0; (1<<i)<=p; ++i)
{
if(((1<<i)&p)>0)
{
sol=(sol*x)%mod;
}
x=(x*x)%mod;
}
return sol;
}
int main()
{
int n, p;
f >> n >> p;
g << log(n, p);
return 0;
}