Find numbers a and b that satisfy the given conditions | C ++ implementation of the above approach ; Function to print the required numbers ; Suppose b = n and we want a % b = 0 and also ( a / b ) < n so a = b * ( n - 1 ) ; Special case if n = 1 we get a = 0 so ( a * b ) < n ; If no pair satisfies the conditions ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void find ( int n ) { int b = n ; int a = b * ( n - 1 ) ; if ( a * b > n && a / b < n ) { cout << " a ▁ = ▁ " << a << " , ▁ b ▁ = ▁ " << b ; } else cout << -1 << endl ; } int main ( ) { int n = 10 ; find ( n ) ; return 0 ; }