Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int cmmdc2(int x, int y)
  4. {
  5. int r;
  6. while(y)
  7. {
  8. r=x%y;
  9. x=y;
  10. y=r;
  11. }
  12. return x;
  13. }
  14. int cmmdc(int v[],int a,int b)
  15. {
  16. int r;
  17. while(b)
  18. {
  19. r=a%b;
  20. a=b;
  21. b=r;
  22. }
  23. return a;
  24. }
  25. int divimp(int v[],int st,int dr)
  26. {
  27. if(st==dr)
  28. return v[st];
  29. else
  30. {
  31. int m=(st+dr)/2;
  32. int cm1=cmmdc(v,st,m);
  33. int cm2=cmmdc(v,m+1,dr);
  34. return cmmdc2(cm1,cm2);
  35. }
  36. }
  37. int main()
  38. {
  39. int n,i,v[1001];
  40. cin>>n;
  41. for(i=1; i<=n; i++)
  42. cin>>v[i];
  43. cout<<divimp(v,1,n);
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement