判断素数
#include <iostream>
#include <cmath>
using namespace std;
bool IsDivides (const int &a, const int &b)
{
return (b % a == 0);
}
int FindDivisor (const int &n, int &&test_divisor)
{
if (pow(test_divisor, 2) > n) {
return n;
}
if (IsDivides (test_divisor, n)) {
return test_divisor;
}
else {
test_divisor += 2;
return FindDivisor (n, move(test_divisor));
}
}
int SmallestDivisor (const int &n)
{
if (IsDivides (2, n)) {
return 2;
}
return FindDivisor (n, 3);
}
bool IsPrimer (const int &n)
{
return (n == SmallestDivisor(n));
}
int main ()
{
cout << SmallestDivisor(19999);
cout << endl;
return 0;
}