Cod sursa(job #1490595)
| Utilizator | Data | 23 septembrie 2015 20:30:30 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.37 kb |
#include<fstream>
using namespace std;
const int m=199999;
int putere(int n, int p)
{
int x=1;
while(p)
{
if(p&1)
{x=(1LL*x*n)%m;
p--;
}
p/=2;
n=(1LL*n*n)%m;
}
return x;
}
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int a,n;
fin>>a>>n;
fout<<putere(a,n);
return 0;
}
