10666

#include <iostream>
#include <cstdio>

using namespace std;
//no of 1' indicate how many times at least it lost a game
//no of 0' indicate how many times at least it lost a game
//so if a team id does not contain a 0 it can be the last of the tournament at it pessimist decision
int NoOfRounds;
int TeamNo;
int TwosPower[31];

int main()
{
	int t;
	int countOne;
	int countZero;
	scanf("%d",&t);
	TwosPower[0]=1;
	for(int i=1;i<31;i++)
		TwosPower[i]=TwosPower[i-1]<<1;
	while(t--)
	{
		scanf("%d%d",&NoOfRounds,&TeamNo);
		int tmp = TeamNo;
		countOne=0;
		while(tmp)
		{
			if(tmp%2)
			countOne+=1;
			tmp = tmp>>1;
		}
		//to find the worst case : after the first lost rest of the game can be considered as lost
		//so find the the first lost=first 1 from the left
		//from this we can find least number of winning match
		//subtract this from total number of matches of that tournaments.
		//each zero from the left means the team is better than the rest of the players of that round.
		tmp = TeamNo;
		countZero=0;
		int i=0;
		while(i<NoOfRounds)
		{
			if(tmp%2)
			break;
			else
			countZero+=TwosPower[i++];
			tmp=tmp>>1;
		}
		printf("%d %d\n",countOne+1,TwosPower[NoOfRounds]-countZero);
	}
	return 0;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *