Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int cmmdc2(int x, int y)
- {
- int r;
- while(y)
- {
- r=x%y;
- x=y;
- y=r;
- }
- return x;
- }
- int cmmdc(int v[],int a,int b)
- {
- int r;
- while(b)
- {
- r=a%b;
- a=b;
- b=r;
- }
- return a;
- }
- int divimp(int v[],int st,int dr)
- {
- if(st==dr)
- return v[st];
- else
- {
- int m=(st+dr)/2;
- int cm1=cmmdc(v,st,m);
- int cm2=cmmdc(v,m+1,dr);
- return cmmdc2(cm1,cm2);
- }
- }
- int main()
- {
- int n,i,v[1001];
- cin>>n;
- for(i=1; i<=n; i++)
- cin>>v[i];
- cout<<divimp(v,1,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement