Cod sursa(job #1195415)
Utilizator | Data | 7 iunie 2014 10:02:32 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include<fstream>
#define MOD 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
inline int putere(int n,int p)
{
long long sol = 1;
while(p > 0)
{
if(p & 1)
{
-- p;
sol = (1LL * sol * n) % MOD;
}
else
{
p /= 2;
n *= n;
}
}
return sol;
}
int main()
{
int n,p;
f >> n >> p;
g << putere(n , p);
}