text: Sum of prime numbers without odd prime digits |  ; 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: #include <bits/stdc++.h> NEW_LINE using namespace std ; #define MAX  100005 NEW_LINE vector < int > addPrimes ( ) { int n = MAX ; bool prime [ n + 1 ] ; memset ( prime , true , sizeof ( prime ) ) ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } vector < int > ans ; for ( int p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) ans . push_back ( p ) ; return ans ; } bool is_prime ( int n ) { return ( n == 3 n == 5 n == 7 ) ; } int find_Sum ( int n ) { int sum = 0 ; vector < int > v = addPrimes ( ) ; for ( int i = 0 ; i < v . size ( ) and n ; i ++ ) { int flag = 1 ; int a = v [ i ] ; while ( a != 0 ) { int d = a % 10 ; a = a / 10 ; if ( is_prime ( d ) ) { flag = 0 ; break ; } } if ( flag == 1 ) { n -- ; sum = sum + v [ i ] ; } } return sum ; } int main ( ) { int n = 7 ; cout << find_Sum ( n ) ; return 0 ; }