#include <gmp.h>
#include <iostream>
using namespace std;
int isprime(unsigned long n)
{
if (n % 2 == 0)
return 0;
if (n % 3 == 0)
return 0;
if (n % 5 == 0)
return 0;
if (n % 7 == 0)
return 0;
if (n % 11 == 0)
return 0;
if (n % 13 == 0)
return 0;
if (n % 17 == 0)
return 0;
if (n % 19 == 0)
return 0;
mpz_t z;
mpz_init_set_ui(z, n);
return mpz_probab_prime_p(z, 4);
}
int main( void )
{
unsigned long y, m, d, n;
for (y = 1600; y <= 9999; y ++)
for (m = 1; m <= 12; m ++)
for (d = 1; d <= 31; d ++)
{
if ((m == 4) || (m == 6) || (m == 9) || (m == 11))
if (d > 30)
continue;
if (y % 4 != 0)
{
if (d > 28)
continue;
}
else
if ((y % 100 != 0) || (y % 400 == 0))
{
if (d > 29)
continue;
}
else
if (d > 28)
continue;
n = 10000 * y + 100 * m + d;
int r = isprime(n);
if (r != 0)
{
if (r == 2)
cout << "生日素数" << n << endl;
else
cout << "可能生日素数" << n << endl;
}
}
}
页:
1
[2]