Prime points ( Points that split a number into two primes ) | C ++ program to print all prime points ; 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 Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countDigits ( int n ) { int count = 0 ; while ( n > 0 ) { count ++ ; n = n / 10 ; } return count ; } int checkPrime ( int n ) { if ( n <= 1 ) return -1 ; if ( n <= 3 ) return 0 ; if ( n % 2 == 0 n % 3 == 0 ) return -1 ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return -1 ; return 0 ; } void printPrimePoints ( int n ) { int count = countDigits ( n ) ; if ( count == 1 count == 2 ) { cout << " - 1" ; return ; } bool found = false ; for ( int i = 1 ; i < ( count - 1 ) ; i ++ ) { int left = n / ( ( int ) pow ( 10 , count - i ) ) ; int right = n % ( ( int ) pow ( 10 , count - i - 1 ) ) ; if ( checkPrime ( left ) == 0 && checkPrime ( right ) == 0 ) { cout << i << " ▁ " ; found = true ; } } if ( found == false ) cout << " - 1" ; } int main ( ) { int n = 2317 ; printPrimePoints ( n ) ; return 0 ; }