- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Here we will see one interesting problem, we will find a pair (x, y), where x and y are in range so l <= x, y <= r, the pair will have one property, the value of x divides y. If there are multiple pairs available, then choose only one.

We can solve this problem in O(1) time, if we get the value of lower limit l and 2l. We know that the smallest value of y/x can be 2, and if some greater value is present in the range then 2 will be in range. And if we increase x, it will also increase 2x, so l and 2l will be the minimum pair to fall in given range.

#include<iostream> using namespace std; void getPair(int l, int r) { int x = l; int y = 2 * l; cout << "(" << x << ", " << y << ")" << endl; } int main() { int l = 3, r = 6; getPair(l, r); }

(3, 6)

- Related Questions & Answers
- Find number of pairs (x, y) in an array such that x^y > y^x in C++
- Count of pairs (x, y) in an array such that x < y in C++
- Count Distinct Non-Negative Integer Pairs (x, y) that Satisfy the Inequality x*x + y*y < n in C++
- Find maximum among x^(y^2) or y^(x^2) where x and y are given in C++
- Find larger of x^y and y^x in C++
- Count Distinct Non-Negative Integer Pairs (x, y) that Satisfy the Inequality x*x +\ny*y < n in C++
- Find the smallest number X such that X! contains at least Y trailing zeros in C++
- Find smallest values of x and y such that ax – by = 0 in C++
- Find minimum x such that (x % k) * (x / k) == n in C++
- Check if a number can be expressed as x^y (x raised to power y) in C++
- Maximize the value of x + y + z such that ax + by + cz = n in C++
- Find minimum positive integer x such that a(x^2) + b(x) + c >= k in C++
- What is ternary operator (? X : Y) in C++?
- Find Four points such that they form a square whose sides are parallel to x and y axes in C++
- Find the value of the function Y = (X^6 + X^2 + 9894845) % 981 in C++

Advertisements