Cod sursa(job #1587451)
| Utilizator | Data | 2 februarie 2016 02:09:18 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int n,p;
int putere(int a,int b)
{
if(b==1)
return a%MOD;
else
{
if(b%2==1)
return (a*putere(a,b-1))%MOD;
else
{
int c = (putere(a,b/2))%MOD;
return (c*c)%MOD;
}
}
}
int main()
{
in>>n>>p;
in.close();
out<<putere(n,p);
out.close();
return 0;
}
