Given an integer ‘n’, the task is to check whether the sum of digits at the odd positions (from right to left) is prime or not.
If it is prime then, print “YES” or “NO” otherwise.
Input: n = 123
As, 1 + 3 = 4 is not prime.
Input: n = 42
Since, 2 is a prime.
Approach: First, find the sum of the digits which are at odd positions i.e, 1, 3, 5, … (starting from right).
If the sum is prime then print ‘YES’ else print ‘NO’.
Below is the implementation of the above approach:
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.
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Check whether sum of digits at odd places of a number is divisible by K
- Find the sum of digits of a number at even and odd places
- Check if product of digits of a number at even and odd places is equal
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Primality Test | Set 1 (Introduction and School Method)
- Primality Test | Set 2 (Fermat Method)
- Primality Test | Set 3 (Miller–Rabin)
- Primality Test | Set 4 (Solovay-Strassen)
- Lucas Primality Test
- AKS Primality Test
- Primality Test | Set 5(Using Lucas-Lehmer Series)
- Vantieghems Theorem for Primality Test
- Implementation of Wilson Primality test
- Check whether product of digits at even places of a number is divisible by K
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Arrangement of the characters of a word such that all vowels are at odd places
- Count of numbers in range which are divisible by M and have digit D at odd places
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
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.