# Check whether the sum of absolute difference of adjacent digits is Prime or not

Given a number a **N** and the task is to check weather the sum of absolute difference of adjacent digit is a prime or not.

**Examples:**

Input:N = 142Output:Prime Sum = |1-4| + |4-2| = 5 i.e. prime.Input:N = 347Output:Not prime

**Approach**: Find the sum of absolute difference of adjacent digits and then check if that sum is prime or not.

Below is the implementation of the above approach:

`# Python3 implementation of the above approach ` `import` `math as mt ` ` ` `# Function to check for a prime number ` `def` `Prime(n): ` ` ` ` ` `if` `n ` `=` `=` `1` `: ` ` ` `return` `False` ` ` ` ` `for` `i ` `in` `range` `(` `2` `, mt.ceil(mt.sqrt(n ` `+` `1` `))): ` ` ` `if` `n ` `%` `i ` `=` `=` `0` `: ` ` ` `return` `False` ` ` `return` `True` ` ` `# Function to find the sum of array ` `def` `checkSumPrime(string): ` ` ` `summ ` `=` `0` ` ` `for` `i ` `in` `range` `(` `1` `, ` `len` `(string)): ` ` ` `summ` `+` `=` `abs` `(` `int` `(string[i` `-` `1` `])` `-` `int` `(string[i])) ` ` ` ` ` `if` `Prime(summ): ` ` ` `return` `True` ` ` `else` `: ` ` ` `return` `False` ` ` `# Driver code ` `num ` `=` `142` ` ` `string ` `=` `str` `(num) ` ` ` `s ` `=` `[i ` `for` `i ` `in` `string] ` ` ` `if` `checkSumPrime(s): ` ` ` `print` `(` `"Prime"` `) ` `else` `: ` ` ` `print` `(` `"Not Prime\n"` `) ` |

*chevron_right*

*filter_none*

**Output:**

Prime

## Recommended Posts:

- Arrange first N natural numbers such that absolute difference between all adjacent elements > 1
- Pair of prime numbers with a given sum and minimum absolute difference
- Minimum absolute difference of a number and its closest prime
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime
- Check if difference of areas of two squares is prime
- Print prime numbers with prime sum of digits in an array
- Minimum absolute difference between N and a power of 2
- Find the node whose absolute difference with X gives minimum value
- Find the node whose absolute difference with X gives maximum value
- Pair with minimum absolute difference after solving each query
- Python program to find sum of absolute difference between all pairs in a list
- Count maximum elements of an array whose absolute difference does not exceed K
- Quick ways to check for Prime and find next Prime in Java

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.