Check n ^ 2 | CPP program to find n ^ 2 - m ^ 2 is prime or not . ; Check a number is prime or not ; run a loop upto square of given number ; Check if n ^ 2 - m ^ 2 is prime ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isprime ( int x ) { for ( int i = 2 ; i * i <= x ; i ++ ) if ( x % i == 0 ) return false ; return true ; } bool isNSqMinusnMSqPrime ( int m , int n ) { if ( n - m == 1 and isprime ( m + n ) ) return true ; else return false ; } int main ( ) { int m = 13 , n = 16 ; if ( isNSqMinusnMSqPrime ( m , n ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }