Unprimeable Numbers | C ++ Program to check if n is unprimeable Number ; function to check if N is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; function to check if n is a unprimeable Number ; number should be composite ; converting N to string ; loop to change digit at every character one by one . ; loop to store every digit one by one at index j ; Driver code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } bool isUnPrimeableNum ( int N ) { if ( isPrime ( N ) ) return false ; string s = to_string ( N ) ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { string str = s ; for ( int i = 0 ; i <= 9 ; i ++ ) { char c = '0' + i ; str [ j ] = c ; int Num = stoi ( str ) ; if ( str [ j ] != s [ j ] && isPrime ( Num ) ) { return false ; } } } return true ; } int main ( ) { int n = 200 ; if ( isUnPrimeableNum ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }