Check if a number is Full Prime | CPP program for checking of full prime ; function to check digits ; check all digits are prime or not ; check if digits are prime or not ; To check if n is prime or not ; check for all factors ; To check if n is Full Prime ; The order is important here for efficiency . ; Driver code to check the above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkDigits ( int n ) { while ( n ) { int dig = n % 10 ; if ( dig != 2 && dig != 3 && dig != 5 && dig != 7 ) return false ; n /= 10 ; } return true ; } bool prime ( int n ) { if ( n == 1 ) return false ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } int isFullPrime ( int n ) { return ( checkDigits ( n ) && prime ( n ) ) ; } int main ( ) { int n = 53 ; if ( isFullPrime ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }