Advertisement
maxim_shlyahtin

0938

Jul 17th, 2022
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <cmath>
  5. #include <algorithm>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. bool prime(int n) {
  11.     for (int i = 2; i < sqrt(n) + 1; i++) {
  12.         if (n % i == 0) { return false; }
  13.     }
  14.     return true;
  15. }
  16.  
  17. int div(int n) {
  18.     int count = 0;
  19.     for (int i = 2; i <= n; i++) {
  20.         if (n % i == 0 && prime(i)) { count++; }
  21.     }
  22.     return count;
  23. }
  24.  
  25. int min(int a, int b) {
  26.     if (a < b) { return a; }
  27.     else { return b; }
  28. }
  29.  
  30. int main() {
  31.     int n, ans = 0;
  32.     cin >> n;
  33.     vector<int> vec;
  34.     sort(vec.begin(), vec.end());
  35.     for (int i = 0; i < n; i++) {
  36.         int k;
  37.         cin >> k;
  38.         vec.push_back(k);
  39.     }
  40.     int c = 0, c1 = 0;
  41.     for (int i = 0; i < n; i++) {
  42.         c = div(vec[i]);
  43.         if (c1 < c) {
  44.             ans = vec[i];
  45.             c1 = c;
  46.         }
  47.         else if (c1 == c) {
  48.             ans = min(ans, vec[i]);
  49.         }
  50.     }
  51.     cout << ans;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement