# Python | Count the array elements with factors less than or equal to the factors of given x

Given an array, the task is to count the elements of array whose factors are less than the given number x.

Examples:

Input: arr = [2, 12, 4, 6], x = 6
Output: 2
factors of x = 6 is [1, 2, 3]
factors of arr = 2 is 
factors of arr = 12 is [1, 2, 3, 4]
factors of arr = 4 is [1, 2]
factors of arr = 6 is [1, 2, 3]

so only arr and arr are the answer.

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach:
Find out factors of all the elements and that of given xand after that compare all of them if factors of elements are less than that of factors of x, then increment the count.

Below is the implementation of above problem –

 `from` `math ``import` `ceil, sqrt ` `  `  `# function to count the factors of an array ` `def` `factorscount(x): ` `    ``count ``=` `0` `    ``for` `i ``in` `range``(``1``,ceil(sqrt(x))): ` `        ``if` `x``%``i``=``=``i: ` `            ``count``+``=``1` `        ``else``: ` `            ``count``+``=``2` `    ``return` `count ` `  `  `def` `Totalcount(arr, x): ` `     `  `    ``# count of factors of  given x ` `    ``count_fac ``=` `factorscount(x) ` `     `  `    ``# store the count of each factors ` `    ``arr_fac ``=` `[factorscount(i) ``for` `i ``in` `arr] ` `  `  `    ``ans ``=` `0` `  `  `    ``for` `i ``in` `arr_fac: ` `        ``# if factors count of element of array is ` `        ``#small than that of given number ` `        ``if` `i

Output:

```2
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.