- Related Questions & Answers
- Count all possible N digit numbers that satisfy the given condition in C++
- Count index pairs which satisfy the given condition in C++
- Find permutation of first N natural numbers that satisfies the given condition in C++
- Find all pairs (a,b) and (c,d) in array which satisfy ab = cd in C++
- Find a palindromic string B such that given String A is a subsequence of B in C++
- Find four elements a, b, c and d in an array such that a+b = c+d in C++
- Find all pairs (a, b) in an array such that a % b = k in C++
- Find the missing value from the given equation a + b = c in Python
- C# Program to check whether the elements of a sequence satisfy a condition or not
- Maximum size of sub-array that satisfies the given condition in C++
- Find largest d in array such that a + b + c = d in C++
- PHP program to find the numbers within a given array that are missing
- Find the final X and Y when they are Altering under given condition in C++
- Find the number of ways to divide number into four parts such that a = c and b = d in C++
- Find records in MongoDB that does NOT match a condition?

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

Consider we have an integer n. Our task is to find two numbers a and b, where these three conditions will be satisfied.

- a mod b = 0
- a * b > n
- a / b < n

If no pair is found, print -1.

For an example, if the number n = 10, then a and b can be a = 90, b = 10. This satisfies given rules.

To solve this problem, we will follow these steps −

- Let b = n. a can be found using these three conditions
- a mod b = 0 when a is multiple of b
- a / b < n, so a / b = n – 1 which is < n
- (a * b > n) => a = n

#include<iostream> using namespace std; void findAandB(int n) { int b = n; int a = b * (n - 1); if (a * b > n && a / b < n) { cout << "a: " << a << endl; cout << "b: " << b; }else cout << -1 << endl; } int main() { int n = 10; findAandB(n); }

a: 90 b: 10

Advertisements