F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

K. Three Operations

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 386    Accepted Submission(s): 198


Problem Description
Given three integers $x, a, b$. You can do the following three operations several times:

- set $x$ to $x - 1$;
- set $x$ to $\lfloor \dfrac{x+a}{2} \rfloor$;
- set $x$ to $\lfloor \sqrt{x+b} \rfloor$.

Calculate the smallest number of operations to set $x$ to $0$.
 

Input
The input consists of multiple test cases. The first line contains a single integer $T$ ($1 \le T \le 2 \times 10 ^ 4$) - the number of test cases. Description of the test cases follows.

The first line of each test case contains three integers $x, a, b$ ($0\leq x, a, b \leq 10 ^ {18}$).
 

Output
For each test case, print one integer - the smallest number of operations to set $x$ to $0$.
 

Sample Input
5 1 1 4 5 1 4 19 1 9 8 1 0 1145141919810 114514 1919810
 

Sample Output
1 4 5 3 1389
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 23:35:35, Gzip enabled