Advertisement
SergeyPGUTI

6.2.3

Nov 20th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double fastmult(double a,int n)
  7. {
  8.     if (n<0) { a=1.0/a;
  9.                n=-n;
  10.              }
  11.     if (n>=1)
  12.     {
  13.         if (n%2!=0) return a*fastmult(a,n-1);
  14.             else return fastmult(a,n/2)*fastmult(a,n/2);
  15.     }
  16.     else
  17.         return 1;
  18. }
  19.  
  20. int main()
  21. {
  22.     double a;
  23.     int n;
  24.     cin>>a>>n;
  25.     cout<<fastmult(a,n);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement