The Hotel with Infinite Rooms

The city of HaluaRuti has a strange hotel with infinite rooms. The groups that come to this hotel follow the following rules:

a) At the same time only members of one group can rent the hotel.

b) Each group comes in the morning of the check-in day and leaves the hotel in the evening of the check-out day.

c) Another group comes in the very next morning after the previous group has left the hotel.

d) A very important property of the incoming group is that it has one more member than its previous group unless it is the starting group. You will be given the no of members of the starting group.

e) A group with n members stays for n days in the hotel. For example, if a group of four members comes on 1st August in the morning, it will leave the hotel on 4th August in the evening and the next group of five members will come on 5th August in the morning and stay for five days and so on.

Given the initial group size you will have to find the group size staying in the hotel on a specified day.

The input contains round numbers S(1<=S<=10000) and D(1<=D<10^15) in every line. S denotes the initial size of the group and D denotes that you will have to find the group size staying in the hotel on D th day (starting from 1). All the input and output integers will be less than 10^15. A group size S means that on the first day a group of S members come to the hotel and stays for S days then comes a group of S+1 members according to the previously described rules and so on.

For each line of input, print on a single line the size of the group staying in the hotel on the D th day.

Sample Input:
1 6
3 10
3 14

Sample Output:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            int initialSize = 2;
            int day = 10;
            for (int i = 1, j = 0; i <= day; i++)
                if (j < initialSize)
                    j = 1;
                Console.WriteLine(“Day: ” + i + ” –> Group Size: ” + initialSize);
            Console.WriteLine(“Size of the group on day ” + day + ” is: ” + initialSize);
Day: 1 --> Group Size: 2
Day: 2 --> Group Size: 2
Day: 3 --> Group Size: 3
Day: 4 --> Group Size: 3
Day: 5 --> Group Size: 3
Day: 6 --> Group Size: 4
Day: 7 --> Group Size: 4
Day: 8 --> Group Size: 4
Day: 9 --> Group Size: 4
Day: 10 --> Group Size: 5
Size of the group on day 10 is: 5
Press any key to continue . . .
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s