Cod sursa(job #2029776)
Utilizator | Data | 30 septembrie 2017 13:45:07 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
#define ll long long
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
ll x,n;
ll f(ll x,ll n){
if(n==0)
return 1;
if (n==1)
return x%1999999973;
if(n%2==0)
return f(x*x%1999999973, n/2)%1999999973;
else
return x*f(x*x%1999999973, (n-1)/2)%1999999973;
}
int main(){
fin>>x>>n;
fout<<f(x,n);
return 0;
}