text: Sum of prime numbers without odd prime digits | Javascript program for above approach ; Find all prime numbers ; Store all prime numbers ; Function to check if a digit is odd prime or not ; Function to find sum ; To store required answer ; Get all prime numbers ; Traverse through all the prime numbers ; Flag stores 1 if a number does not contain any odd primes ; Find all digits of a number ; If number does not contain any odd primes ; Return the required answer ; Driver code ; Function call
code: const MAX = 100005 ; function addPrimes ( ) { let n = MAX ; let prime = new Array ( n + 1 ) . fill ( true ) ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } let ans = [ ] ; for ( let p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) ans . push ( p ) ; return ans ; } function is_prime ( n ) { return ( n == 3 n == 5 n == 7 ) ; } function find_Sum ( n ) { let sum = 0 ; let v = addPrimes ( ) ; for ( let i = 0 ; i < v . length && n > 0 ; i ++ ) { let flag = 1 ; let a = v [ i ] ; while ( a != 0 ) { let d = a % 10 ; a = parseInt ( a / 10 ) ; if ( is_prime ( d ) ) { flag = 0 ; break ; } } if ( flag == 1 ) { n -- ; sum = sum + v [ i ] ; } } return sum ; } let n = 7 ; document . write ( find_Sum ( n ) ) ;