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