FANDOM


#include <iostream>

using namespace std;

// Returns true if an only if a divides by b evenly
#define divides(a,b) (((a) % (b)) == 0)

template< int n, int i, int c >
class _is_prime
{
    _is_prime< (i > 1 ? n : 0), i - 1, (c && !divides (n, i)) > v;
public:
    int value ()
    {
        return i == 2 ? c : v.value ();
    }
};

template<>
class _is_prime< 0, 0, 0 >
{
public:
    int value ()
    {
        return 0;
    }
};

template< int n >
class is_prime
{
    _is_prime< n, n-1, 1 > v;
public:
    int value ()
    {
        return v.value ();
    }
};

void main ()
{
  is_prime< 11 > p11;
  is_prime< 12 > p12;
  is_prime< 13 > p13;
  is_prime< 14 > p14;
  is_prime< 15 > p15;

  cout << "is_prime (11) = " << p11.value () << "\n"
       << "is_prime (12) = " << p12.value () << "\n"
       << "is_prime (13) = " << p13.value () << "\n"
       << "is_prime (14) = " << p14.value () << "\n"
       << "is_prime (15) = " << p15.value () << "\n";
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.