Check out example codes for "check prime no for large value in cpp". It will help you in understanding the concepts better.

Code Example 1

#include <iostream>
using namespace std;

int main()
{
  int n, i;
  bool isPrime = true;

  cout << "Enter a positive integer: ";
  cin >> n;

  for(i = 2; i <= n / 2; ++i)
  {
      if(n % i == 0)
      {
          isPrime = false;
          break;
      }
  }
  if (isPrime)
      cout << "This is a prime number";
  else
      cout << "This is not a prime number";

  return 0;
}

Code Example 2

// A optimized school method based C++ program to check 
// if a number is prime 
#include <bits/stdc++.h> 
using namespace std; 
  
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    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; 
} 
  
// Driver Program to test above function 
int main() 
{ 
    isPrime(11) ? cout << " true\n" : cout << " false\n"; 
    isPrime(15) ? cout << " true\n" : cout << " false\n"; 
    return 0; 
}

Learn ReactJs, React Native from akashmittal.com