Advertisement
MathQ_

Untitled

Jul 6th, 2021
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
  2. #pragma GCC optimize 03
  3. #pragma GCC optimize("unroll-loops")
  4.  
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <algorithm>
  8. #include <iterator>
  9. #include <cmath>
  10. #include <ctime>
  11. #include <vector>
  12. #include <deque>
  13. #include <queue>
  14. #include <set>
  15. #include <map>
  16. #include <stack>
  17. #include <string>
  18. #include <random>
  19. #include <numeric>
  20. #include <unordered_set>
  21. #include <unordered_map>
  22. #include <ext/pb_ds/assoc_container.hpp>
  23. #include <ext/pb_ds/tree_policy.hpp>
  24.  
  25. using namespace std;
  26. using namespace __gnu_pbds;
  27.  
  28. typedef std::pair<int, int> pii;
  29. typedef std::pair<char, char> pcc;
  30. typedef std::pair<short, char> psc;
  31. typedef unsigned long long ull;
  32. typedef long long ll;
  33. typedef long double lb;
  34. typedef tree<int,
  35.              null_type,
  36.              less<int>,
  37.              rb_tree_tag,
  38.              tree_order_statistics_node_update> ordered_set;
  39.  
  40. #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  41. #define file_in freopen("input.txt", "r", stdin);
  42. #define file_in_out freopen("commander.in", "r", stdin); freopen("commander.out", "w", stdout);
  43. #define all(x) (x).begin(), (x).end()
  44. #define fi first
  45. #define se second
  46.  
  47. template<typename T>
  48. istream& operator>>(istream &in, vector<T> &v) {
  49.     for (auto &it : v) {
  50.         in >> it;
  51.     }
  52.     return in;
  53. }
  54.  
  55. template<typename T>
  56. ostream& operator<<(ostream &out, const vector<T> &v) {
  57.     for (auto &it : v) {
  58.         out << it << " ";
  59.     }
  60.     return out;
  61. }
  62.  
  63. template<typename T1, typename T2>
  64. istream& operator>>(istream &in, pair<T1, T2> &v) {
  65.     in >> v.fi >> v.se;
  66.     return in;
  67. }
  68.  
  69. template<typename T1, typename T2>
  70. ostream& operator<<(ostream &out, const pair<T1, T2> &v) {
  71.     out << v.fi << " " << v.se;
  72.     return out;
  73. }
  74.  
  75. int main() {
  76.     fast
  77.     // file_in
  78.     // file_in_out
  79.     int n;
  80.     cin >> n;
  81.     vector<int> a(n);
  82.     cin >> a;
  83.     gp_hash_table<int, pair<gp_hash_table<int, int>, pii>> pr;
  84.     for (auto j : a) {
  85.         for (int i = 2, c = 0; i * i <= j; ++i, c = 0) {
  86.             while (j % i == 0) {
  87.                 ++c; j /= i;
  88.             }
  89.             if (pr[i].fi[c] == 0) {
  90.                 pr[i].se.se = c;
  91.             } else {
  92.                 pr[i].se.se = min(pr[i].se.se, c);
  93.             }
  94.             pr[i].fi[c]++; pr[i].se.fi++;
  95.         }
  96.         if (j != 1) {
  97.             if (pr[j].fi[1] == 0) {
  98.                 pr[j].se.se = 1;
  99.             } else {
  100.                 pr[j].se.se = min(pr[j].se.se, 1);
  101.             }
  102.             pr[j].fi[1]++; pr[j].se.fi++;
  103.         }
  104.     }
  105.     int ans = n;
  106.     for (auto el : pr) {
  107.         if (el.se.se.fi == 0) continue;
  108.         if (el.se.se.fi < n) {
  109.             ans = min(ans, el.se.fi[0] + n - el.se.se.fi);
  110.         } else {
  111.             ans = min(ans, el.se.fi[el.se.se.se]);
  112.         }
  113.        
  114.     }
  115.     cout << (ans == n ? -1 : ans) << '\n';
  116.     return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement