Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
- #pragma GCC optimize 03
- #pragma GCC optimize("unroll-loops")
- #include <iostream>
- #include <iomanip>
- #include <algorithm>
- #include <iterator>
- #include <cmath>
- #include <ctime>
- #include <vector>
- #include <deque>
- #include <queue>
- #include <set>
- #include <map>
- #include <stack>
- #include <string>
- #include <random>
- #include <numeric>
- #include <unordered_set>
- #include <unordered_map>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- typedef std::pair<int, int> pii;
- typedef std::pair<char, char> pcc;
- typedef std::pair<short, char> psc;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double lb;
- typedef tree<int,
- null_type,
- less<int>,
- rb_tree_tag,
- tree_order_statistics_node_update> ordered_set;
- #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- #define file_in freopen("input.txt", "r", stdin);
- #define file_in_out freopen("commander.in", "r", stdin); freopen("commander.out", "w", stdout);
- #define all(x) (x).begin(), (x).end()
- #define fi first
- #define se second
- template<typename T>
- istream& operator>>(istream &in, vector<T> &v) {
- for (auto &it : v) {
- in >> it;
- }
- return in;
- }
- template<typename T>
- ostream& operator<<(ostream &out, const vector<T> &v) {
- for (auto &it : v) {
- out << it << " ";
- }
- return out;
- }
- template<typename T1, typename T2>
- istream& operator>>(istream &in, pair<T1, T2> &v) {
- in >> v.fi >> v.se;
- return in;
- }
- template<typename T1, typename T2>
- ostream& operator<<(ostream &out, const pair<T1, T2> &v) {
- out << v.fi << " " << v.se;
- return out;
- }
- int main() {
- fast
- // file_in
- // file_in_out
- int n;
- cin >> n;
- vector<int> a(n);
- cin >> a;
- gp_hash_table<int, pair<gp_hash_table<int, int>, pii>> pr;
- for (auto j : a) {
- for (int i = 2, c = 0; i * i <= j; ++i, c = 0) {
- while (j % i == 0) {
- ++c; j /= i;
- }
- if (pr[i].fi[c] == 0) {
- pr[i].se.se = c;
- } else {
- pr[i].se.se = min(pr[i].se.se, c);
- }
- pr[i].fi[c]++; pr[i].se.fi++;
- }
- if (j != 1) {
- if (pr[j].fi[1] == 0) {
- pr[j].se.se = 1;
- } else {
- pr[j].se.se = min(pr[j].se.se, 1);
- }
- pr[j].fi[1]++; pr[j].se.fi++;
- }
- }
- int ans = n;
- for (auto el : pr) {
- if (el.se.se.fi == 0) continue;
- if (el.se.se.fi < n) {
- ans = min(ans, el.se.fi[0] + n - el.se.se.fi);
- } else {
- ans = min(ans, el.se.fi[el.se.se.se]);
- }
- }
- cout << (ans == n ? -1 : ans) << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement