Prime points ( Points that split a number into two primes ) | Function to count number of digits ; Function to check whether a number is prime or not . Returns 0 if prime else - 1 ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to print prime points ; Counting digits ; As single and double digit numbers do not have left and right number pairs ; Finding all left and right pairs . Printing the prime points accordingly . Discarding first and last index point ; Calculating left number ; Calculating right number ; Prime point condition ; No prime point found ; Driver Code
function countDigits ( n ) { let count = 0 ; while ( n > 0 ) { count ++ ; n = Math . floor ( n / 10 ) ; } return count ; } function checkPrime ( n ) { if ( n <= 1 ) return - 1 ; if ( n <= 3 ) return 0 ; if ( n % 2 == 0 n % 3 == 0 ) return - 1 ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return - 1 ; return 0 ; } function printPrimePoints ( n ) { let count = countDigits ( n ) ; if ( count == 1 count == 2 ) { document . write ( " " ) ; return ; } let found = false ; for ( let i = 1 ; i < ( count - 1 ) ; i ++ ) { let left = Math . floor ( n / ( Math . pow ( 10 , count - i ) ) ) ; let right = n % ( Math . pow ( 10 , count - i - 1 ) ) ; if ( checkPrime ( left ) == 0 && checkPrime ( right ) == 0 ) { document . write ( i + " " ) ; found = true ; } } if ( found == false ) document . write ( " " ) ; } let n = 2317 ; printPrimePoints ( n ) ;