757B - Bash's Big Day - CodeForces Solution


greedy math number theory *1400

Please click on ads to support us..

C++ Code:

#include "bits/stdc++.h"
using namespace std; 

using ll = long long; 

const int N = 1e5 + 1;
vector <int> primes;
vector <bool> f(N, 0); 



void solve () {
    int n; cin >> n; 
    // vector <int> v;
    int h[N] = {0}; 
    for (int i = 0; i < n; i++) {
    	int y; cin >> y;
    	h[y]++;
    }
    int ans = 1; 
    for (int i = 2; i < N; i += 1) {
    	int res = 0; 
    	for (int j = i; j < N; j += i) {
    		res += h[j];
    	}
    	ans = max(ans, res); 
    }
    cout << ans << '\n';
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //pre(); 
  //  cin >> t;
    for (int i = 1; i <= t; i++) {
      solve();
    }
    return 0; 
}
								 					         					 		


Comments

Submit
0 Comments
More Questions

1469A - Regular Bracket Sequence
919C - Seat Arrangements
1634A - Reverse and Concatenate
1619C - Wrong Addition
1437A - Marketing Scheme
1473B - String LCM
1374A - Required Remainder
1265E - Beautiful Mirrors
1296A - Array with Odd Sum
1385A - Three Pairwise Maximums
911A - Nearest Minimums
102B - Sum of Digits
707A - Brain's Photos
1331B - Limericks
305B - Continued Fractions
1165B - Polycarp Training
1646C - Factorials and Powers of Two
596A - Wilbur and Swimming Pool
1462B - Last Year's Substring
1608B - Build the Permutation
1505A - Is it rated - 2
169A - Chores
765A - Neverending competitions
1303A - Erasing Zeroes
1005B - Delete from the Left
94A - Restoring Password
1529B - Sifid and Strange Subsequences
1455C - Ping-pong
1644C - Increase Subarray Sums
1433A - Boring Apartments