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

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
raja
Updated on 15-Mar-2022 05:25:28

Advertisements