Ad

Various functions related to prime numbers.

class PrimeNumber {
  public:
    // Check if given number is prime or not.
    static bool isPrime(unsigned long long num )  {
        if(num <= 1) return false;
        for( long long i = 2; (long long) i * i <= num; i++) 
            if( num % i == 0) return false;
        return true;
    }
};