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


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).

Steps

To solve this, we will follow these steps −

return l and l*2

Example

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);
}

Input

3, 14

Output

3, 6

Updated on: 15-Mar-2022

274 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements