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.
Input: N = 142 Output: Prime Sum = |1-4| + |4-2| = 5 i.e. prime. Input: N = 347 Output: 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:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Arrange first N natural numbers such that absolute difference between all adjacent elements > 1
- Minimize the maximum absolute difference of adjacent elements in a circular array
- 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
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Sort elements of an array in increasing order of absolute difference of adjacent elements
- 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
- Sum of prime numbers without odd prime digits
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Quick ways to check for Prime and find next Prime in Java
- Check if a prime number can be expressed as sum of two Prime Numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.