Just Arrange the Icons

BerPhone X is almost ready for release with nn n applications being preinstalled on the phone. A category of an application characterizes a genre or a theme of this application (like "game", "business", or "education"). The categories are given as integers between 11 1 and nn n , inclusive; the ii i -th application has category c**ici c_i .

You can choose mm m — the number of screens and ss s — the size of each screen. You need to fit all nn n icons of the applications (one icon representing one application) meeting the following requirements:

  • On each screen, all the icons must belong to applications of the same category (but different screens can contain icons of applications of the same category);

  • Each screen must be either completely filled with icons (the number of icons on the screen is equal to

ss

) or almost filled with icons (the number of icons is equal to

s−1s−1

).

Your task is to find the minimal possible number of screens mm m .

Input

The first line contains an integer tt t (1≤t≤100001≤t≤10000 1 \le t \le 10,000 ) — the number of test cases in the input. Then tt t test cases follow.

The first line of each test case contains an integer nn n (1≤n≤2⋅1061≤n≤2⋅106 1 \le n \le 2\cdot10^6 ) — the number of the icons. The second line contains nn n integers c1,c2,…,c**nc1,c2,…,cn c_1, c_2, \dots, c_n (1≤c**in1≤ci≤n 1 \le c_i \le n ), where c**ici c_i is the category of the ii i -th application.

It is guaranteed that the sum of the values of nn n for all test cases in the input does not exceed 2⋅1062⋅106 2\cdot10^6 .

Output

Print tt t integers — the answers to the given test cases in the order they follow in the input. The answer to a test case is an integer mm m — the minimum number of screens on which all nn n icons can be placed satisfying the given requirements.

Example

Input

Copy

3
11
1 5 1 5 1 5 1 1 1 1 5
6
1 2 2 2 2 1
5
4 3 3 1 2

Output

Copy

3
3
4

Note

In the first test case of the example, all the icons can be placed on three screens of size 44 4 : a screen with 44 4 icons of the category 11 1 , a screen with 33 3 icons of the category 11 1 , and a screen with 44 4 icons of the category 55 5 .

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f;
const int N=1e6+5;
//int num[2*N];
vector<int>vt;
int x[2*N];
int main()
{
    int t,n;
    //cin>>t;
    scanf("%d",&t);

    while(t--)
    {
       // cin>>n;
       vt.clear();
          int mi=INF,mx=-1,p;
    //int cnt=0;
      // cnt=0;
       scanf("%d",&n);
      //  memset(num,0,sizeof(num));
        memset(x,0,sizeof(x));
        for(int i=0;i<n;i++)
        {
            //cin>>num[i];
            scanf("%d",&p);
            x[p]++;
            mx=max(mx,p);
        }
        for(int i=0;i<=mx;i++)
        {
            if(x[i]==0) continue;
            else
            {
              //num[cnt++]=x[i];
              vt.push_back(x[i]);  //vector速度比数组快 ,用于统计数量
              mi=min(mi,x[i]);
            }
        }
        int tot,r=0;
        int minn=INF;

            int ans=0;
            for(int i=1;i<=mi+1;i++)
            {

                r=0;
                ans=0;
                //for(int j=0;j<cnt;j++)
                for(auto X :vt)
                {
                    tot=(X-1)/i+1;
                    if(X%i==0) ans+=X/i;
                    else if(X-tot*(i-1)>=0&&X-tot*i<=0) ans+=tot;
                    else
                    {
                       r=-1;
                       break;
                    }
                }
                if(r!=-1)
                    minn=min(minn,ans);

            }
            //cout<<ans<<endl;
            printf("%d\n",minn);
    }
    return 0;
}

思路:

image-20200905185131841

x=(c-1)/s+1;

posted @ 2020-09-05 18:54  Anticlock  阅读(175)  评论(0编辑  收藏  举报