C++ code to find pair of numbers where one is multiple of other

C++Server Side ProgrammingProgramming

Suppose we have two numbers l and r. We have to find such pair (x, y), such that l <= x, y <= r, and x != y and x divides y. If there are more than one answer, return any one of them.

So, if the input is like l = 3; r = 14, then the output will be (3, 9).


To solve this, we will follow these steps −

return l and l*2


Let us see the following implementation to get better understanding −

#include <bits/stdc++.h>
using namespace std;
void solve(int l, int r){
   cout << l << ", " << l * 2;
int main(){
   int l = 3;
   int r = 14;
   solve(l, r);


3, 14


3, 6
Updated on 15-Mar-2022 05:25:28