Cod sursa(job #1897648)
Utilizator | Data | 1 martie 2017 16:53:58 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 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)
{
p *= x % mod;
}
x *= x % mod;
}
return p;
}
int main()
{
int n, p;
f >> n >> p;
g << log(n, p);
return 0;
}