Sum of primes
Basic Accuracy: 45.56% Submissions: 2660 Points: 1

Your task is to calculate sum  of primes present as digits of given number N.

Example 1:

Input: 333
Output: 9
Explaination: 3 is a prime number. It 
is present 3 times. So 3+3+3 = 9.

Example 2:

Input: 686
Output: 0
Explaination: Neither 6 nor 8 is a 
prime number.

Your Task:
You do not need to read input or print anything. Your task is to complete the function primeSum() which takes N as input parameter and returns the sum of all the prime digits present in the number N.

Expected Time Complexity: O(logN)
Expected Auxiliary Space: O(1)

Constraints:
1 ≤ N ≤ 5*104   

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Sum of primes

Output Window