Codeforces 1108B Divisors of Two Integers Solution

Solve in C++:


  1. ///**********ALLAH IS ALMIGHTY************///
  2. ///AH Tonmoy
  3. ///Department of CSE
  4. ///Islamic University,Bangladesh
  5. #include<iostream>
  6. #include<math.h>
  7. #include<algorithm>
  8. #include<vector>
  9. using namespace std;
  10. int main()
  11. {
  12. int n,ar[10009]= {0},i,mx=0,c=0,c1=0,s1[10009]= {0},s2[10009]= {0},t1[10009]= {0};
  13. while(cin>>n)
  14. {
  15. s1[10009]= {0};
  16. for(i=0; i<n; i++)
  17. {
  18. cin>>ar[i];
  19.  
  20. }
  21. sort(ar,ar+n);
  22. mx=ar[n-1];
  23. s1[ar[n-1]]=1;
  24. cout<<mx<<" ";
  25. ar[n-1]=0;
  26. for(i=0;i<n-1;i++)
  27. {
  28. if((s1[ar[i]]==0)&&(mx%ar[i]==0))
  29. {
  30. s1[ar[i]]=1;
  31. ar[i]=0;
  32. }
  33. }
  34. sort(ar,ar+n);
  35. cout<<ar[n-1]<<endl;
  36. }
  37. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.