Cod sursa(job #1512530)
| Utilizator | Data | 28 octombrie 2015 10:48:16 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.33 kb |
#include <fstream>
using namespace std;
ifstream in ("lgput.in");
ofstream out ("lgput.out");
int main()
{ int n,p,r=1 ;
in >>n >>p;
while (p!=1)
{
if (p%2==0)
{
p=p/2 ;
n=(n*n)%199999973 ;}
else{ p=(p-1)%199999973 ;
r=r*n ;
}}
n=n*r ;
out<<n ;
return 0;
}
