- Related Questions & Answers
- Count pairs with bitwise OR less than Max in C++
- Count pairs with sum as a prime number and less than n in C++
- Count pairs in a sorted array whose product is less than k in C++
- Count number of ordered pairs with Even and Odd Product in C++
- Count all subsequences having product less than K in C++
- Subarray Product Less Than K in C++
- Count pairs in a sorted array whose sum is less than x in C++
- Count number of ordered pairs with Even and Odd Sums in C++
- Find maximum product of digits among numbers less than or equal to N in C++
- Count pairs of numbers from 1 to N with Product divisible by their Sum in C++
- Find unique pairs such that each element is less than or equal to N in C++
- C++ program to find unique pairs such that each element is less than or equal to N
- Count all the numbers less than 10^6 whose minimum prime factor is N C++
- Print all numbers less than N with at-most 2 unique digits in C++
- Count of alphabets having ASCII value less than and greater than k in C++

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

We are given a number N. The goal is to find ordered pairs of positive numbers such that their product is less than N.

We will do this by starting from i=1 to i<N and j=1 to (i*j)<N. Then increment count.

Let’s understand with examples.

**Input**

N=4

**Output**

Ordered pairs such that product is less than N:5

**Explanation**

Pairs will be (1,1) (1,2) (1,3) (2,1) (3,1)

**Input**

N=100

**Output**

Ordered pairs such that product is less than N: 473

**Explanation**

Pairs will be (1,1) (1,2) (1,3)....(97,1), (98,1), (99,1). Total 473.

We take integer N.

Function productN(int n) takes n and returns the count of ordered pairs with product < n

Take the initial variable count as 0 for pairs.

Traverse using two for loops for making pairs.

Start from i=1 to i<n. And j=1 to (i* j)<n.

Increment count by 1.

At the end of all loops count will have a total number of such pairs.

Return the count as result.

#include <bits/stdc++.h> using namespace std; int productN(int n){ int count = 0; for (int i = 1; i < n; i++){ for(int j = 1; (i*j) < n; j++) { count++; } } return count; } int main(){ int N = 6; cout <<"Ordered pairs such that product is less than N:"<<productN(N); return 0; }

If we run the above code it will generate the following output −

Ordered pairs such that product is less than N:10

Advertisements