Calculator

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has a calculator which has two screens and two buttons. Initially, each screen shows the number zero. Pressing the first button increments the number on the first screen by 1, and each click of the first button consumes 1 unit of energy.
Pressing the second button increases the number on the second screen by the number which is currently appearing on the first screen. Each click of the second button consumes B units of energy.
Initially the calculator has N units of energy.
Now chef wonders what the maximum possible number is, that he gets on the second screen of the calculator, with the limited energy.
Input
The first line of the input contains an integer T denoting the number of test cases.
Each test case is described using a single line containing two integers, N and B.
Output
For each test case, output a single line containing the answer to this test case.
Constraints
 1 ≤ T ≤ 10,000
 1 ≤ N, B ≤ 1,000,000,000
Subtasks
 Subtask 1 (20 points): 1 ≤ N, B ≤ 1,000
 Subtask 2 (80 points): Original constraints
Example
Input: 3 10 2 8 5 6 1 Output: 12 3 9
Explanation
Example case 1. There are 10 units of energy available. Pressing second button takes 2 units of energy. Chef can achieve 12 on the second screen as follows.
 Press first button to get scores (1, 0). 9 units of energey is left.
 Press first button to get scores (2, 0). 8 units of energy remaining.
 Press first button to get scores (3, 0). 7 units of energy remaining.
 Press first button to get scores (4, 0). 6 units of energy remaining.
 Press second button to get scores (4, 4). 4 units of energy remaining.
 Press second button to get scores (4, 8). 2 units of energy remaining.
 Press second button to get scores (4, 12). 0 units of energy remaining.
Author:  kingofnumbers 
Editorial  https://discuss.codechef.com/problems/CALC 
Tags  easy, july17, kingofnumbers, math, simplemath 
Date Added:  4072017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions