Cod sursa(job #1471586)
| Utilizator | Data | 14 august 2015 15:30:57 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
using namespace std;
int n,p;
long long expo(int baza, int exp)
{
if(exp==0)
return 1;
else
{
long long tmp=expo(baza,exp/2)%1999999973;
if(exp%2)
return (tmp*tmp*baza)%1999999973;
else
return (tmp*tmp)%1999999973;
}
}
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
f>>n>>p;
g<<expo(n,p)%1999999973;
f.close();
g.close();
return 0;
}
