Advertisement
jakaria_hossain

codeforce - Divisors of Two Integers

Mar 6th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fastread()(ios_base::sync_with_stdio(false),cin.tie(NULL));
  4. #define ll long long
  5. int main()
  6. {
  7. fastread()
  8. ll n;
  9. cin>>n;
  10. ll ara[n+1],mx=0,i,j,mn=0,sub=0;
  11. map<ll,ll>mp;
  12. for(i=0;i<n;i++)
  13. {
  14. cin>>ara[i];
  15. mx=max(mx,ara[i]);
  16. mp[ara[i]]++;
  17. if(mp[ara[i]]>mn)
  18. {
  19. mn=mp[ara[i]];
  20. sub=ara[i];
  21. }
  22. if(mp[ara[i]]==mn)
  23. {
  24. sub=max(ara[i],sub);
  25. }
  26. }
  27. sort(ara,ara+n);
  28. i=n-1;
  29. while(i>=0)
  30. {
  31. if(mx%ara[i]!=0)
  32. {
  33. mn=ara[i];
  34. break;
  35. }
  36. i--;
  37. }
  38. if(i<0)mn=sub;
  39. cout<<mx<<" "<<mn<<endl;
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement