Cod sursa(job #2043505)
| Utilizator | Data | 20 octombrie 2017 09:55:10 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int exp_lg (int x, int p)
{
if(p==1) return x%mod;
if(p==0) return 1;
int z;
z=exp_lg(x,p/2);
if(p%2==0) return z*z%mod;
return z*z*x%mod;
}
int main()
{
int N, P;
f>>N>>P;
cout<<P;
g<<exp_lg(N,P);
f.close();
g.close();
}
