Advertisement
Dani_info

cmmdc a n nr

Mar 5th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int cmmdc(int st, int dr, int x[])
  5. {
  6.     int m,m1,m2,r;
  7.     if(st==dr)
  8.         return x[st];
  9.     else
  10.     {
  11.         m=(st+dr)/2;
  12.         m1=cmmdc(st,m,x);
  13.         m2=cmmdc(m+1,dr,x);
  14.         r=m1%m2;
  15.         while(r)
  16.         {
  17.             m1=m2;
  18.             m2=r;
  19.             r=m1%m2;
  20.        }
  21.         return m2;
  22.     }
  23. }
  24.  
  25. int main()
  26. {
  27.     int n, x[100],i;
  28.     cin>>n;
  29.     for(i=1; i<=n; i++)
  30.         cin>>x[i];
  31.     cout<<cmmdc(1,n,x);
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement