Good God's question...
First, we only need to enumerate this GCD .. From big to small, and then the problem is converted into a judgment problem... Determine whether there is a K number and a GCD number ..
Orz
The worst complexity is O (n + n/2 + N/3 +... + N/n) = O (nlnn), proving that Google "harmonic series summation ".
#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <iostream>#include <algorithm>#include <queue>#include <set>#include <map>using namespace std;typedef long long ll;#define pii pair<int, int>#define mkpii make_pair<int, int>#define pdi pair<double, int>#define mkpdi make_pair<double, int>#define pli pair<ll, int>#define mkpli make_pair<ll, int>#define rep(i, n) for(int i=0; i<(n); ++i)#define for1(i,a,n) for(int i=(a);i<=(n);++i)#define for2(i,a,n) for(int i=(a);i<(n);++i)#define for3(i,a,n) for(int i=(a);i>=(n);--i)#define for4(i,a,n) for(int i=(a);i>(n);--i)#define CC(i,a) memset(i,a,sizeof(i))#define read(a) a=getint()#define print(a) printf("%d", a)#define dbg(x) cout << (#x) << " = " << (x) << endl#define error(x) (!(x)?puts("error"):0)#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }#define printarr1(a, b) for1(_, 1, b) cout << a[_] << ‘\t‘; cout << endlinline const int getint() { int r=0, k=1; char c=getchar(); for(; c<‘0‘||c>‘9‘; c=getchar()) if(c==‘-‘) k=-1; for(; c>=‘0‘&&c<=‘9‘; c=getchar()) r=r*10+c-‘0‘; return k*r; }inline const int max(const int &a, const int &b) { return a>b?a:b; }inline const int min(const int &a, const int &b) { return a<b?a:b; }int n, f[500005], K;int main() {read(n); read(K);int mx=0;for1(i, 1, n) { int t=getint(); ++f[t]; mx=max(t, mx); }for3(i, mx, 1) {int sum=0;for(int k=1; k*i<=mx; ++k) sum+=f[k*i];if(sum>=K) {printf("%lld\n", 1ll*i*1ll*K);return 0;}}return 0;}
[Problem description]
In other words, CD is relatively not flat. He said that it was too lonely to beat him in the classroom, so this night, he finally came to the computer room to be beaten. Since CD is a pet of everyone, everyone is playing CD. There are n people in the computer room, and I people want to play CD AI. However, if too many people play CD, they will get upset again, so he requires that only K people can hit him, and for the sake of fairness, the number of times K people beat him must be the same, CD specifies that this number of times is the maximum number of times that the K individual wants to beat him. Why is it the largest common appointment? Because he thinks that the number of times he was beaten is GCD, then he will become gglad CD. As mentioned before, CD is relatively not flat, so CD hopes that K people will beat him the most frequently. Can you tell him how much he will be beaten in the end?
[Input format]
The first line has two positive integers, N and K.
The n positive integers in the second line indicate the number of CDs that each user wants to play.
[Output format]
Output a positive integer indicating the number of times the CD is played.
[Example input and output]
GCD. In |
GCD. Out |
3 1 1 2 3 |
3 |
|
|
[Data description]
For 30% of the data, ensure K ≤ n ≤ 20.
For 50% of the data, make sure that the number in the input is smaller than 5000.
For 100% of the data, make sure that the number in the input is less than 500000, K is less than or equal to n.
[Noip simulation questions] maximum number of public appointments (number theory)