Saraff's New Shop
Practice
3.2 (4 votes)
Combinatorics
Math
Medium
Number theory
Problem
41% Success 1191 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Saraff is planning to open a general store in his locality. He is planning to buy a weight balance and some weights to measure weights in the store.

There is a single store Pahi's Weight Store which sells balance and weights in Saraff's country. Pahi's store has K pieces of each positive integral weight and buying all K pieces of a weight costs 1 Rupee. For each integral weight, you can either not take it, or take K pieces of it and pay 1 Rupee.

Saraff wants to find what minimum amount of money he needs to spend so that he is able to measure all the positive integral weights \(\le N\). To measure a weight X, he needs some pieces such that the sum of their values equals X.

INPUT CONSTRAINTS

  • \(1 \le T \le 10^5\)
  • \(1 \le K \le 10^6\)
  • \(1 \le N \le 10^{18}\)

INPUT FORMAT
First line of input contains a single integer T, denoting number of test case. Each test case contains two space separated integers K and N.

OUTPUT FORMAT
Print the minimum amount of money he needs to spend so that Saraff is able to measure all the positive integral weights \(\le N\). To measure a weight X, he needs some pieces such that the sum of their values equals X.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
2 votes
Tags:
AlgorithmsMathCombinatoricsBasics of Combinatorics
Points:30
7 votes
Tags:
CombinatoricsBasics of CombinatoricsMathC++
Points:30
2 votes
Tags:
CombinatoricsGeometryMathMediumMeet in the middle