Numbers II
Practice
4.3 (18 votes)
Algorithms
Binary search
Greatest common divisor
Medium
Searching
Gcd
Problem
13% Success 13870 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Given two numbers a and b, you have to find the \(N^{th}\) number which is divisible by a or b.
Input :
First line consists of an integer T, denoting the number of test cases.
Second line contains three integers a, b and N .
Output :
For each test case, print the \(N^{th}\) number in a new line.
Constraints :
\(1 \le t \le 10^5\)
\(1 \le a ,b \le 10^4\)
\(1 \le N \le 10^9\)
Explanation
The numbers which are divisible by 2 or 3 are: \(2,3,4,6,8,9,10,12,14,15\) and the \(10^{th}\) number is \(15\).
Code Editor
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
88 votes
Tags:
ApprovedBinary SearchMediumOpenSorting
Points:50
14 votes
Tags:
Modular arithmeticHardApprovedModular exponentiationMathematicsNumber TheoryMatrix Exponentiation
Points:30
18 votes
Tags:
AlgorithmsBinary SearchMediumPrefix sumSearchingTwo pointerprefix-sum
Editorial
Login to unlock the editorial
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
Results
Custom Input
Run your code to see the output