rotti321

exponentiere rapida

Sep 21st, 2021
537
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int p(int a,int n){ ///exponentiere rapida
  6.     if(n==0) return 1;
  7.     if(n%2==1)  return a*p(a,n-1);
  8.     else{
  9.         int x=p(a,n/2);
  10.         return x*x;
  11.     }        
  12. }
  13.  
  14. int main() {
  15.     int a, n;
  16.     cin >> a >> n;
  17.     cout<<p(a,n);
  18.     return 0;
  19. }
RAW Paste Data