Codechef Malvika conducts a Programming Camp

      No Comments on Codechef Malvika conducts a Programming Camp

Codechef Malvika conducts a Programming Camp Problem Code: CHN05

Codechef Malvika conducts a Programming Camp – problem statement

After acquiring an extraordinary amount of knowledge through programming contests, Malvika decided to harness her expertise to train the next generation of Indian programmers. So, she decided to hold a programming camp. In the camp, she held a discussion session for n members (n-1 students, and herself). They are sitting in a line from left to right numbered through 1 to n.

Malvika is sitting in the nth spot. She wants to teach m topics of competitive programming to the students. As the people taking part in the camp are all newbies, they know none of the topics being taught, i.e., initially, the first n – 1 people in the line know none of the topics, while the nth knows all of them.

It takes one hour for a person to learn a topic from his neighbour. Obviously, one person cannot both teach a topic as well as learn one during the same hour. That is, in any particular hour, a person can either teach a topic that he knows to one of his neighbors, or he can learn a topic from one of his neighbors, or he can sit idly. It is also obvious that if person x is learning from person y at a particular hour, then person y must be teaching person x at that hour. Also, note that people can work parallely too, i.e., in the same hour when the 4th person is teaching the 3rd person, the 1st person can also teach the 2nd or learn from 2nd.

Find out the minimum number of hours needed so that each person learns all the m topics.

Input

The first line of input contains a single integer T denoting number of test cases.
The only line of each test case contains two space separated integers n, m as defined in the statement.

Output

For each test case, output a single integer in a line corresponding to the answer of the problem.

Constraints

1 ≤ T, n, m ≤ 100

Example

Input:

2
2 1
3 2

Solution in C:

#include<stdio.h>
void main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m,d;
        scanf("%d%d",&n,&m);
        if(n==2)
        {
            printf("%d\n",m);
        }
        else if(n==1)
        {
            printf("0\n");
        }
 
        else
        {
 
            printf("%d\n",(n-1)+2*(m-1));
        }
 
 
    }
}

Codechef Malvika conducts a Programming Camp

Summary
Codechef Malvika conducts a Programming Camp
Article Name
Codechef Malvika conducts a Programming Camp
Description
Codechef Malvika conducts a Programming Camp After acquiring an extraordinary amount of knowledge through programming contests, Malvika decided to harness her expertise to train the next generation of Indian programmers. So, she decided to hold a programming camp. In the camp, she held a discussion session for n members (n-1 students, and herself). They are sitting in a line from left to right numbered through 1 to n.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

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