Additive Prime Number | Check if N is prime or not ; Corner Cases ; This is checked to skip middle five numbers ; Function to get sum of digits ; Return the sum of digits ; Function to check whether the given number is Additive Prime number or not ; If number is not prime ; Check if sum of digits is prime or not ; Given Number N ; Function Call
function isPrime ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } function getSum ( n ) { let sum = 0 ; while ( n != 0 ) { sum = sum + n % 10 ; n = n / 10 ; } return sum ; } function isAdditivePrime ( n ) { if ( ! isPrime ( n ) ) return false ; return isPrime ( getSum ( n ) ) ; } let n = 23 ; if ( isAdditivePrime ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;