Given two integer **N** and **X**. **N** represents the number of rows and columns of a table. And the element at the **ith** row and the** jth** column in the table is **i*j**. The task is to find the number of cells in the table contains **X**.

**Examples:**

Input :N = 6, X = 12

Output :4

Cells {2, 6}, {3, 4}, {4, 3}, {6, 2} contains the number 12

Input :N = 5, X = 11

Output :0

**Approach:**

It’s easy to see that number **x** can appear only once in a row. If **x** contains in the **ith** row then the column number will be **x/i**. **x** contains in the **ith** row if **x** is divisible by **i**. let’s check that **x** divides **i** and **x/i** **<= n**. If these conditions met then update the answer.

Below is the implementation of the above approach :

## C++

`// CPP program to find number of ` `// cells in the table contains X ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find number of ` `// cells in the table contains X ` `int` `Cells(` `int` `n, ` `int` `x) ` `{ ` ` ` `int` `ans = 0; ` ` ` `for` `(` `int` `i = 1; i <= n; i++) ` ` ` `if` `(x % i == 0 && x / i <= n) ` ` ` `ans++; ` ` ` ` ` `return` `ans; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 6, x = 12; ` ` ` ` ` `// Function call ` ` ` `cout << Cells(n, x); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find number of ` `// cells in the table contains X ` `class` `GFG ` `{ ` ` ` ` ` `// Function to find number of ` ` ` `// cells in the table contains X ` ` ` `public` `static` `int` `Cells(` `int` `n, ` `int` `x) ` ` ` `{ ` ` ` `int` `ans = ` `0` `; ` ` ` `for` `(` `int` `i = ` `1` `; i <= n; i++) ` ` ` `if` `(x % i == ` `0` `&& x / i <= n) ` ` ` `ans++; ` ` ` ` ` `return` `ans; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `int` `n = ` `6` `, x = ` `12` `; ` ` ` ` ` `// Function call ` ` ` `System.out.println(Cells(n, x)); ` ` ` `} ` `} ` ` ` `// This code is contributed by sanjeev2552 ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find number of ` `# cells in the table contains X ` ` ` `# Function to find number of ` `# cells in the table contains X ` `def` `Cells(n, x): ` ` ` ` ` `ans ` `=` `0` `; ` ` ` `for` `i ` `in` `range` `(` `1` `, n ` `+` `1` `): ` ` ` `if` `(x ` `%` `i ` `=` `=` `0` `and` `x ` `/` `i <` `=` `n): ` ` ` `ans ` `+` `=` `1` `; ` ` ` ` ` `return` `ans; ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `'__main__'` `: ` ` ` ` ` `n ` `=` `6` `; x ` `=` `12` `; ` ` ` ` ` `# Function call ` ` ` `print` `(Cells(n, x)); ` ` ` `# This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find number of ` `// cells in the table contains X ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find number of ` ` ` `// cells in the table contains X ` ` ` `static` `int` `Cells(` `int` `n, ` `int` `x) ` ` ` `{ ` ` ` `int` `ans = 0; ` ` ` `for` `(` `int` `i = 1; i <= n; i++) ` ` ` `if` `(x % i == 0 && x / i <= n) ` ` ` `ans++; ` ` ` ` ` `return` `ans; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `n = 6, x = 12; ` ` ` ` ` `// Function call ` ` ` `Console.WriteLine(Cells(n,x)); ` ` ` `} ` `} ` ` ` `// This code is contributed by nidhiva ` |

*chevron_right*

*filter_none*

**Output:**

4

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Count of cells in a matrix whose adjacent cells's sum is prime Number
- Find Number of Even cells in a Zero Matrix after Q queries
- Count of cells in a matrix which give a Fibonacci number when the count of adjacent cells is added
- Minimum Numbers of cells that are connected with the smallest path between 3 given cells
- Find the sum of the costs of all possible arrangements of the cells
- Find whether there is path between two cells in matrix
- Find safe cells in a matrix
- Find cells in Matrix that are not visited by Robot for given movements
- Number of cells in the Nth order figure
- Number of cells in a matrix that satisfy the given condition
- Number of cells in matrix which are equidistant from given two points
- Queries to find the count of connected Non-Empty Cells in a Matrix with updates
- Total number of unit cells covered by all given Rectangles
- Number of cells a queen can move with obstacles on the chessborad
- Number of cells in the right and left diagonals passing through (x, y) in a matrix
- Total number of cells covered in a matrix after D days
- Min number of moves to traverse entire Matrix through connected cells with equal values
- Number of ways to paint K cells in 3 x N grid such that no P continuous columns are left unpainted
- Multiplication table till N rows where every Kth row is table of K upto Kth term
- Compute the parity of a number using XOR and table look-up

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.