Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstdlib>
- using namespace std;
- const int MAXA = 500 * 1000 + 5;
- int lDiv[MAXA], ans = MAXA * 10;
- vector<int> prDiv[MAXA], pr;
- void gen(int x, vector<int> a, int res) {
- bool ok = true;
- for(size_t i = 0; i < a.size(); i++) {
- res += a[i] / x;
- a[i] %= x;
- if(a[i])
- ok = false;
- }
- if(ok) {
- ans = min(ans, res);
- return;
- }
- if(res >= ans)
- return;
- for(size_t i = 0; i < prDiv[x].size(); i++)
- gen(x / prDiv[x][i], a, res);
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- srand(time(0));
- for(int i = 2; i < MAXA; i++) {
- if(!lDiv[i]) {
- lDiv[i] = i;
- pr.push_back(i);
- }
- for(size_t j = 0; j < pr.size() && pr[j] <= lDiv[i]; j++) {
- int p = pr[j] * i;
- if(p >= MAXA)
- break;
- lDiv[p] = pr[j];
- }
- }
- for(int i = 2; i < MAXA; i++) {
- int x = i;
- while(x > 1) {
- int y = lDiv[x];
- prDiv[i].push_back(y);
- while(!(x % y))
- x /= y;
- }
- }
- int n = 7;
- cin >> n;
- vector<int> a(n);
- int maxa = 0;
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- maxa = max(maxa, a[i]);
- }
- for(int i = max(maxa / 2, 1); i <= maxa; i++)
- gen(i, a, 0);
- cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement