# Find if a number is divisible by every number in a list

Given a list and a number task is to find the number which is divided by every element of the list.

**Examples :**

Input : List = [1, 2, 3, 4, 5] Number = 3 Output : No Input : List = [4, 8, 12, 16, 20] Number = 4 Output : Yes

**Algorithm:**

1. Run a loop till length of the list 2. Divide every element with the given number 3. If number is not divided by any element, return 0. 4. Return 1.

## C++

`// C++ program which check is a number ` `// divided with every element in list or not ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function which check is a number ` `// divided with every element in list or not ` `bool` `findNoIsDivisibleOrNot(` `int` `a[], ` `int` `n, ` `int` `l) ` `{ ` ` ` `for` `(` `int` `i = 0; i < l; i++) { ` ` ` `if` `(a[i] % n != 0) ` ` ` `return` `false` `; ` ` ` `} ` ` ` `return` `true` `; ` `} ` ` ` `// driver program ` `int` `main() ` `{ ` ` ` `int` `a[] = {14, 12, 4, 18}; ` ` ` `int` `n = 2; ` ` ` `int` `l = (` `sizeof` `(a) / ` `sizeof` `(a[0])); ` ` ` `if` `(findNoIsDivisibleOrNot(a, n, l)) ` ` ` `cout << ` `"Yes"` `; ` ` ` `else` ` ` `cout << ` `"No"` `; ` ` ` ` ` `return` `0; ` `} ` ` ` `// This code is contributed by Sam007 ` |

*chevron_right*

*filter_none*

## Java

`// Java program which check is a number ` `// divided with every element in list ` `// or not ` ` ` `class` `GFG { ` ` ` ` ` `// Function which check is a number ` ` ` `// divided with every element in list or not ` ` ` `static` `boolean` `findNoIsDivisibleOrNot(` `int` `a[], ` `int` `n) ` ` ` `{ ` ` ` `for` `(` `int` `i = ` `0` `; i < a.length; i++) { ` ` ` `if` `(a[i] % n != ` `0` `) ` ` ` `return` `false` `; ` ` ` `} ` ` ` `return` `true` `; ` ` ` `} ` ` ` ` ` `// driver program ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `int` `a[] = {` `14` `, ` `12` `, ` `4` `, ` `18` `}; ` ` ` `int` `n = ` `2` `; ` ` ` `if` `(findNoIsDivisibleOrNot(a, n)) ` ` ` `System.out.println(` `"Yes"` `); ` ` ` `else` ` ` `System.out.println(` `"No"` `); ` ` ` `} ` `} ` ` ` `// This code is contributed by Pramod Kumar ` |

*chevron_right*

*filter_none*

## Python

`# Python program which check is a number ` `# divided with every element in list ` `# or not ` `def` `findNoIsDivisibleOrNot(n, l ` `=` `[]): ` ` ` ` ` `# Checking if a number is divided ` ` ` `# by every element or not ` ` ` `for` `i ` `in` `range` `(` `0` `, ` `len` `(l)): ` ` ` `if` `l[i]` `%` `n !` `=` `0` `: ` ` ` `return` `0` ` ` `return` `1` ` ` `# Driver code ` `l ` `=` `[` `14` `, ` `12` `, ` `4` `, ` `18` `] ` `n ` `=` `2` `if` `findNoIsDivisibleOrNot(n, l) ` `=` `=` `1` `: ` ` ` `print` `"Yes"` `else` `: ` ` ` `print` `"No"` |

*chevron_right*

*filter_none*

## C#

`// C# program which check is a number ` `// divided with every element in list or no ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// Function which check is a number ` ` ` `// divided with every element in list or not ` ` ` `static` `bool` `findNoIsDivisibleOrNot(` `int` `[] a, ` `int` `n) ` ` ` `{ ` ` ` `for` `(` `int` `i = 0; i < a.Length; i++) { ` ` ` `if` `(a[i] % n != 0) ` ` ` `return` `false` `; ` ` ` `} ` ` ` `return` `true` `; ` ` ` `} ` ` ` ` ` `// driver program ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `[] a = {14, 12, 4, 18}; ` ` ` `int` `n = 2; ` ` ` `if` `(findNoIsDivisibleOrNot(a, n)) ` ` ` `Console.WriteLine(` `"Yes"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"No"` `); ` ` ` `} ` `} ` ` ` `// This code is contributed by Sam007 ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program which ` `// check is a number ` `// divided with every ` `// element in list or not ` ` ` `// Function which check ` `// is a number divided ` `// with every element ` `// in list or not ` `function` `findNoIsDivisibleOrNot(` `$a` `, ` `$n` `, ` `$l` `) ` `{ ` ` ` `for` `(` `$i` `= 0; ` `$i` `< ` `$l` `; ` `$i` `++) ` ` ` `{ ` ` ` `if` `(` `$a` `[` `$i` `] % ` `$n` `!= 0) ` ` ` `return` `false; ` ` ` `} ` ` ` `return` `true; ` `} ` ` ` ` ` `// Driver Code ` ` ` `$a` `= ` `array` `(14, 12, 4, 18); ` ` ` `$n` `= 2; ` ` ` `$l` `= sizeof(` `$a` `); ` ` ` `if` `(findNoIsDivisibleOrNot(` `$a` `, ` `$n` `, ` `$l` `)) ` ` ` `echo` `"Yes"` `; ` ` ` `else` ` ` `echo` `"No"` `; ` ` ` `// This code is contributed by ajit ` `?> ` |

*chevron_right*

*filter_none*

Output:

Yes

This article is contributed by **Sahil Rajput**. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

## Recommended Posts:

- Find the Kth number which is not divisible by N
- Find N digits number which is divisible by D
- Find nth number that contains the digit k or divisible by k.
- Find the number closest to n and divisible by m
- Find the Nth natural number which is not divisible by A
- Find the first natural number whose factorial is divisible by x
- Find Nth smallest number that is divisible by 100 exactly K times
- Find the maximum number of elements divisible by 3
- Find a N-digit number such that it is not divisible by any of its digits
- Find a N-digit number such that it is not divisible by any of its digits
- Find N numbers such that a number and its reverse are divisible by sum of its digits
- Minimum number of swaps required to make a number divisible by 60
- Number of ways to split a binary number such that every part is divisible by 2
- Check if a number is divisible by all prime divisors of another number
- Number of digits to be removed to make a number divisible by 3
- Number of substrings with length divisible by the number of 1's in it
- Find number from given list for which value of the function is closest to A
- Count the number of pairs (i, j) such that either arr[i] is divisible by arr[j] or arr[j] is divisible by arr[i]
- Number of divisors of a given number N which are divisible by K
- Number is divisible by 29 or not