static bool IsPrimeProof(mpz_t n) { var ns = n.ToString(); var digits = ns.ToCharArray(); char[] digitsCopy = new char[digits.Length]; for (int di = 0; di < digits.Length; di++) { int digit = digits[di]; var low = di == 0 ? '1' : '0'; for (char odigit = low; odigit <= '9'; odigit++) { if (odigit != digit) { Array.Copy(digits, digitsCopy, digits.Length); digitsCopy[di] = odigit; var cand = new mpz_t(new string(digitsCopy)); if (cand.IsProbablyPrimeRabinMiller(10)) { return(false); } } } } return(true); }
static int NumPrimes(int a, int b) { for (int n = 0; ; n++) { mpz_t bign = new mpz_t(n); mpz_t p = bign.Power(2) + bign.Multiply(a) + b; if (!p.IsProbablyPrimeRabinMiller(10)) { return(n); } } }
static bool IsCircular(mpz_t p) { string ps = p.ToString(); if (ps.Length > 1 && telltaleChars.IsMatch(ps)) { return(false); } for (int i = 1; i < ps.Length; i++) { string c = $"{ps.Substring(i)}{ps.Substring(0, i)}"; var pr = new mpz_t(c); if (!pr.IsProbablyPrimeRabinMiller(10)) { return(false); } } return(true); }
static bool IsTruncatable(mpz_t p) { if (p <= 7) { return(false); } var ps = p.ToString(); foreach (var truncate in truncates) { for (string pstrunc = truncate.Replace(ps, string.Empty); pstrunc.Length > 0; pstrunc = truncate.Replace(pstrunc, string.Empty)) { var ptrunc = new mpz_t(pstrunc); if (!ptrunc.IsProbablyPrimeRabinMiller(10)) { return(false); } } } return(true); }