Cod sursa(job #2815400)
Utilizator | Data | 9 decembrie 2021 15:57:11 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include <iostream>
using namespace std;
long long putere(long long a, int n, int m){
if(n==0){
return 1;
}
if(n%2!=0){
return a*putere(a*a%m, (n-1)/2, m)%m;
}else{
return putere(a*a%m, n/2, m);
}
}
int main()
{
int a,n;
cin>>a>>n;
cout<<putere(a,n,1999999973);
return 0;
}