Problem C
The Hotel with Infinite Rooms
Input: standard input
Output: standard output
Time Limit: 2 seconds
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.
Input
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 Ddenotes 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.
Output
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 63 10
3 14
Sample Output:
35
6
大意:有一間客源不會斷的旅館 一次只能有一團人住
N個人住進去 會在裡面待N天 要你求在第N天的時候是幾人團住在裡面
ex: N=4 那麼如果住進去是1號會住到4號 下一團會從5號開始住
import java.util.Scanner;
public class UVA10170 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int start = sc.nextInt();
long end = sc.nextLong();
long count = 0, i = 0, max = 0;
i = start;
while (count < end) {
count += i;
if (max < i)
max = i;
else
break;
i++;
}
System.out.println(max);
}
sc.close();
}
}
留言
張貼留言