Codeforces 1108B Divisors of Two Integers Solution
Solve in C++:
- ///**********ALLAH IS ALMIGHTY************///
- ///AH Tonmoy
- ///Department of CSE
- ///Islamic University,Bangladesh
- #include<iostream>
- #include<math.h>
- #include<algorithm>
- #include<vector>
- using namespace std;
- int main()
- {
- int n,ar[10009]= {0},i,mx=0,c=0,c1=0,s1[10009]= {0},s2[10009]= {0},t1[10009]= {0};
- while(cin>>n)
- {
- s1[10009]= {0};
- for(i=0; i<n; i++)
- {
- cin>>ar[i];
- }
- sort(ar,ar+n);
- mx=ar[n-1];
- s1[ar[n-1]]=1;
- cout<<mx<<" ";
- ar[n-1]=0;
- for(i=0;i<n-1;i++)
- {
- if((s1[ar[i]]==0)&&(mx%ar[i]==0))
- {
- s1[ar[i]]=1;
- ar[i]=0;
- }
- }
- sort(ar,ar+n);
- cout<<ar[n-1]<<endl;
- }
- }
No comments