55 lines
1.0 KiB
C++
55 lines
1.0 KiB
C++
#include <iostream>
|
|
#include <vector>
|
|
#include <cmath>
|
|
#include <algorithm>
|
|
|
|
using namespace std;
|
|
|
|
const int MAX_N = 1000;
|
|
const int MAX_A = 1e9;
|
|
|
|
|
|
vector<int> sieve(int limit) {
|
|
vector<bool> is_prime(limit + 1, true);
|
|
vector<int> primes;
|
|
is_prime[0] = is_prime[1] = false;
|
|
for (int i = 2; i <= limit; ++i) {
|
|
if (is_prime[i]) {
|
|
primes.push_back(i);
|
|
for (int j = i * 2; j <= limit; j += i) {
|
|
is_prime[j] = false;
|
|
}
|
|
}
|
|
}
|
|
return primes;
|
|
}
|
|
|
|
int main() {
|
|
int n;
|
|
cin >> n;
|
|
vector<int> a(n);
|
|
for (int i = 0; i < n; ++i) {
|
|
cin >> a[i];
|
|
}
|
|
|
|
int sqrt_max_a = sqrt(MAX_A);
|
|
vector<int> primes = sieve(sqrt_max_a);
|
|
|
|
int max_sum = 0;
|
|
|
|
|
|
for (int p : primes) {
|
|
int current_sum = 0;
|
|
for (int i = 0; i < n; ++i) {
|
|
if (a[i] % p == 0) {
|
|
current_sum += a[i];
|
|
}
|
|
}
|
|
max_sum = max(max_sum, current_sum);
|
|
}
|
|
|
|
cout << max_sum << endl;
|
|
|
|
return 0;
|
|
}
|