UESTC 1647 Battery Charging(규칙 시뮬레이션 찾기)

Description


Recently, qbwj bought a powerful cellphone which performs even better than most computers. He spent lots of time on it. However, this cellphone has a very strange feature which confused qbwj. There is a battery with infinite capacity in the cellphone. On each day, qbwj has three choices: use the cellphone, charge the battery or do nothing. He cannot do using and charging on the same day. Charging on the kth day adds k units of power to the battery. If qbwj chooses to use the cellphone on the kth day, it would consume k units of power. Note that qbwj can choose to use the cellphone if and only if there are enough units of power in the battery. Despite of the strengths of the cellphone, qbwj couldn't suffer it any more. So he decides to sell it at the end of Tth day. Today is the Sth day and the battery is empty now. He wants to know how many days at maximum he can use the cellphone before selling it out. Note that qbwj can still choose to use the cellphone on both the Sth day and Tth day.

Input


The first line of the input will be an integer N (N <= 10000) indicating the number of cases. For each test case, two integers are given on a single line: S T. 1 <= S <= T <= 108.

Output


Print "Case #k: d"in a single line for each test case, in which k represents the case number which starts from 1, and d is the answer.

Sample Input


3 3 6 3 9 1 100000

Sample Output


Case #1: 1 Case #2: 3 Case #3: 49994

Hint


For the first sample, we charge the cellphone on the 3rd, 4th, 5th day and use it on the 6th day.

Source


10th UESTC Programming Contest Final 
분석: 간단한 욕심, 분명히 배터리를 사용할 수 있는 것은 1, 이후에 사용하면 더 많은 전기를 소비하기 때문이다.2. 이후 충전은 현재 충전보다 더 많은 전력을 얻는다.S일에는 배터리가 방전되고 충전이 끝나면 S의 배터리가 남습니다. S+1일에는 배터리가 부족하기 때문에 충전이 필요합니다. 충전이 끝나면 2*S+1의 배터리가 남습니다. S+2일에는 배터리를 사용하고 다 쓰면 S-1의 배터리가 남습니다. 나중에 이런 절차를 반복합니다. 즉, 하루 충전하고 하루를 사용합니다.이런 절차를 한 번씩 진행할 때마다 남은 전력량을 1씩 줄인다.그래서 S의 전량은 S회 이런 절차를 진행할 수 있고 S일을 사용했다.3*S일, 남은 전력량은 0입니다.그리고 3*S+1일은 같은 문제입니다.매번 3배의 성장을 시뮬레이션하면 되기 때문이다.
내 코드:
#include
#include
#include
using namespace std;
int main()
{
    int t,cas=1,k,a,b,ans;
    scanf("%d",&t);
    while(t--)
    {
        ans=0;
        scanf("%d%d",&a,&b);
        while(a

좋은 웹페이지 즐겨찾기