Cod sursa(job #1897653)
Utilizator | Data | 1 martie 2017 16:56:41 | |
---|---|---|---|
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");
int log(int x, int n)
{
long long p = 1;
for(int i = 0; (1<<i) <= n; ++i)
{
if(((1<<i) & n) > 0)
{
p = (p * x) % mod;
}
x = (x * x) % mod;
}
return p;
}
int main()
{
int n, p;
f >> n >> p;
g << log(n, p);
return 0;
}