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.
- Count numbers from given range having odd digits at odd places and even digits at even places
- 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
- Primality Test | Set 1 (Introduction and School Method)
- Primality Test | Set 3 (Miller–Rabin)
- AKS Primality Test
- Primality Test | Set 5(Using Lucas-Lehmer Series)
- Vantieghems Theorem for Primality Test
- Implementation of Wilson Primality test
- Primality Test | Set 4 (Solovay-Strassen)
- Primality Test | Set 2 (Fermat Method)
- Lucas Primality Test
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- 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
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.