Cod sursa(job #1935291)
| Utilizator | Data | 22 martie 2017 10:27:52 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long n, p;
int wow(int n,int p)
{
if(p==1)
return n%1999999973;
if(p==0)
return 1%1999999973;
if(p%2==1)
return n*wow(n, p-1)%1999999973;
return wow(n, p/2)*wow(n, p/2)%1999999973;
}
int main()
{
f>>n>>p;
if(p==1){g<<n;return 0;}
g<<wow(n, p);
return 0;
}
