Cod sursa(job #675106)
| Utilizator | Data | 7 februarie 2012 10:22:48 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include<fstream>
#define modul 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long temp;
unsigned long long putere (unsigned long long x,unsigned long long y)
{
if (y==0) return 1;
else temp=putere(x,y/2)%modul;
if (y%2==0)
return (temp*temp)%modul;
else if (y%2==1)
return ((x%modul)*(temp*temp)%modul)%modul;
}
int main ()
{
unsigned long long n,p,rez;
f>>n>>p;
rez=putere(n,p)%modul;
g<<rez;
return 0;
}
