Count of ways to split a given number into prime segments | Javascript implementation to count total number of ways to split a string to get prime numbers ; Function to check whether a number is a prime number or not ; Function to find the count of ways to split String into prime numbers ; 1 based indexing ; Consider every suffix up to 6 digits ; Number should not have a leading zero and it should be a prime number ; Return the final result ; Driver code
let MOD = 1000000007 ; function isPrime ( number ) { let num = parseInt ( number ) ; for ( let i = 2 ; i * i <= num ; i ++ ) { if ( ( num % i ) == 0 ) return false ; } return num > 1 ? true : false ; } function countPrimeStrings ( number , i ) { if ( i == 0 ) return 1 ; let cnt = 0 ; for ( let j = 1 ; j <= 6 ; j ++ ) { if ( i - j >= 0 && number [ i - j ] != ' ' && isPrime ( number . substring ( i - j , i ) ) ) { cnt += countPrimeStrings ( number , i - j ) ; cnt %= MOD ; } } return cnt ; } let s1 = " " ; let l = s1 . length ; document . write ( countPrimeStrings ( s1 , l ) ) ;