Project Spoon
|
All submissions for this problem are available.
Lo and Behold! For you may be surprised by what our chief chef Noodle has in mind for this season! Today, Noodle announced one of his most extra-ordinary ideas ever - Project Spoon.
Noodle plans to deploy large spoons in the atmosphere so that people all around the world can download food directly from his kitchen thereby saving him a lot of overhead cost. Yes, you read that right. Large spoons suspended in the atmosphere.
Noodle decides the following strategy to implement his idea. He will deploy exactly N spoons in the country. Every spoon can cater to as many cities as it wants. The only catch is that between every pair of spoons Aand B, A must cater to at-least one city that B doesn't cater to, and B must cater to at-least one city that Adoesn't cater to.
Noodle would like to know what is the minimum number of cities a country must have for his strategy to be successful. Since, he is not all that good with calculation, he asks you to help him with it.
Input
The first line contains an integer T denoting the number of test cases. Each of the next T lines contain an integer N, the number of spoons that Noodle plans to deploy in the country.
Output
For every test case, print in a single line the number of minimum cities required.
Constraints
- 1 ≤ T ≤ 100000
- 2 ≤ N ≤ 1018
Example
Input: 2 2 3 Output: 2 3
Explanation
Example case 1.
Each spoon caters to a different city. Since there are two spoons, two cities are sufficient.
Each spoon caters to a different city. Since there are two spoons, two cities are sufficient.
Example case 2.
Again, each spoon needs to cater to one city and there are three spoons. So, three cities are required at minimum.
Again, each spoon needs to cater to one city and there are three spoons. So, three cities are required at minimum.
Pre-requisites:
Sperner's Theorem
Problem:
Given an integer N, find the size of smallest set S such that there exists an antichain of size N among the subsets of S.
Explanation:
The relation between groups of cities A and B served by two spoons can be equivalently stated as: A-B is not empty andB-A is not empty, which is same as A ⊄ B and B ⊄ A.
If we consider the poset of all subsets of a set S, then the two elements A and B above are incomparable, therefore all the N sub-sets form an antichain.
People could obtain the solution by
- guess work, or,
- evaluating the first few few terms and then using oies to get the required sequence, or,
- reinventing proof of Sperner's Theorem.
The statement and proof of Sperner's Theorem is given below in very simple language.
Given the Sperner's Theorem, we would still need to find smallest M such that M choose ⌊ M/2 ⌋ is at least N. For N ≤ 1018, M ≤ 64, and therefore, one could compute these values offline(or online in his code itself), and do a binary search to lookup the best value. Time complexity O(T).
Proof of Sperner's Theorem
Given a set S of size M, you want to pick a family F of subsets of S (i.e. F ⊂ 2S) such that no set in the family is subset of another set in the family (i.e. x, y ∈ F ⇒ x ⊄ y). The maximum possible size of such a family of subsets is M choose ⌊ M/2 ⌋
It is clear that if we choose all subsets in the family F to be of same size, k, then the family would satisfy the above property, and its size will be M choose k. This is maximum when k=⌊ M/2 ⌋. Therefore, the bound suggested above can be attained by picking all sbsets of size ⌊ M/2 ⌋. Now it remains to show that this is also the best possible bound.
Lets say we have got a family F of subsets satisfying above property, and it has a1 subsets of size 1, a2 subsets of size 2... aM subsets of size M.
Then we can generate a permutation of S by selecting a set S' in F and concatenating a permutation of the elements ofS' with a permutation of the non-members. If |S'| = i, it will be associated in this way with i!(n − i)! permutations. Each permutation can only be associated with at most one set in F. This is because otherwise two different prefixes of a single permutation would be associated with different subsets(say S1 and S2) in F, in which case, one(out of S1 andS2) would be a subset of the other. Therefore, the number of permutations that can be generated by this procedure is
sum [i=1 to M] ai * i! (M-i)!
And the above number is no more than M!. For k=⌊ M/2 ⌋ we already have
sum [i=1 to M] ai * k! (M-k)! ≤ sum [i=1 to M] ai * i! (M-i)! ≤ M!
⇒ sum [i=1 to M] ai ≤ M!/ (k! * (M-k)!)
Setter's Solution:
Can be found here
Tester's Solution:
Editorialist's Solution:
#include<bits/stdc++.h>
using namespace std;
long long int nCr[66][66];
void pre()
{
for(int i=0;i<=65;i++)
nCr[i][0] = 1 ;
for(int i=1;i<=65;i++)
for(int j=1;j<=i;j++)
nCr[i][j] = ( nCr[i-1][j-1] + nCr[i-1][j] ) ;
}
long long int limit[66];
int main()
{
pre();
limit[0]=0;
limit[1]=1;
limit[2]=2;
limit[3]=3;
limit[4]=6;
for(int i=5;i<=65;i++)
{
limit[i]=nCr[i][i/2];
}
int t;
cin>>t;
while(t--)
{
long long int i,n;
cin>>n;
for(i=0;i<=65;i++)
{
if(limit[i]>=n)
{
cout<<i<<endl;
break;
}
}
}
return 0;
}