|
|
Line 84: |
Line 84: |
|
Erdos prime 7875: 999721 |
|
Erdos prime 7875: 999721 |
|
</pre> |
|
</pre> |
|
|
|
|
⚫ |
|
|
⚫ |
<lang csharp>using System; using static System.Console; |
|
⚫ |
|
|
⚫ |
const int lmt = (int)1e6, first = 2500; static int[] f = new int[10]; |
|
⚫ |
static void Main(string[] args) { |
|
⚫ |
f[0] = 1; for (int a = 0, b = 1; b < f.Length; a = b++) |
|
⚫ |
|
|
⚫ |
int pc = 0, nth = 0, lv = 0; |
|
⚫ |
for (int i = 2; i < lmt; i++) if (is_erdos_prime(i)) { |
|
⚫ |
if (i < first) Write("{0,5:n0}{1}", i, pc++ % 5 == 4 ? "\n" : " "); |
|
⚫ |
|
|
⚫ |
Write("\nCount of Erdős primes between 1 and {0:n0}: {1}\n{2} Erdős prime (the last one under {3:n0}): {4:n0}", first, pc, card(nth), lmt, lv); } |
|
|
|
|
⚫ |
static string card(int n) { |
|
⚫ |
return string.Format("{0:n0}", n) + new string[]{"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"}[n % 10]; } |
|
|
|
|
⚫ |
static bool is_erdos_prime(int p) { |
|
⚫ |
if (!is_pr(p)) return false; int m = 0, t; |
|
⚫ |
while ((t = p - f[m++]) > 0) if (is_pr(t)) return false; |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
if (x < 4) return x > 1; if ((x & 1) == 0) return false; |
|
⚫ |
for (int i = 3; i * i <= x; i += 2) if (x % i == 0) return false; |
|
⚫ |
return true; } } }</lang> |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
1,259 1,709 1,831 1,889 2,141 |
|
⚫ |
2,221 2,309 2,351 2,411 2,437 |
|
|
|
|
⚫ |
Count of Erdős primes between 1 and 2,500: 25 |
|
⚫ |
7,875th Erdős prime (the last one under 1,000,000): 999,721</pre> |
|
|
|
|
|
=={{header|C++}}== |
|
=={{header|C++}}== |
Line 147: |
Line 181: |
|
The 7,875th Erdős prime is 999,721. |
|
The 7,875th Erdős prime is 999,721. |
|
</pre> |
|
</pre> |
|
|
|
⚫ |
|
|
⚫ |
<lang csharp>using System; using static System.Console; |
|
⚫ |
|
|
⚫ |
const int lmt = (int)1e6, first = 2500; static int[] f = new int[10]; |
|
⚫ |
static void Main(string[] args) { |
|
⚫ |
f[0] = 1; for (int a = 0, b = 1; b < f.Length; a = b++) |
|
⚫ |
|
|
⚫ |
int pc = 0, nth = 0, lv = 0; |
|
⚫ |
for (int i = 2; i < lmt; i++) if (is_erdos_prime(i)) { |
|
⚫ |
if (i < first) Write("{0,5:n0}{1}", i, pc++ % 5 == 4 ? "\n" : " "); |
|
⚫ |
|
|
⚫ |
Write("\nCount of Erdős primes between 1 and {0:n0}: {1}\n{2} Erdős prime (the last one under {3:n0}): {4:n0}", first, pc, card(nth), lmt, lv); } |
|
|
|
|
⚫ |
static string card(int n) { |
|
⚫ |
return string.Format("{0:n0}", n) + new string[]{"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"}[n % 10]; } |
|
|
|
|
⚫ |
static bool is_erdos_prime(int p) { |
|
⚫ |
if (!is_pr(p)) return false; int m = 0, t; |
|
⚫ |
while ((t = p - f[m++]) > 0) if (is_pr(t)) return false; |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
if (x < 4) return x > 1; if ((x & 1) == 0) return false; |
|
⚫ |
for (int i = 3; i * i <= x; i += 2) if (x % i == 0) return false; |
|
⚫ |
return true; } } }</lang> |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
1,259 1,709 1,831 1,889 2,141 |
|
⚫ |
2,221 2,309 2,351 2,411 2,437 |
|
|
|
|
⚫ |
Count of Erdős primes between 1 and 2,500: 25 |
|
⚫ |
7,875th Erdős prime (the last one under 1,000,000): 999,721</pre> |
|
|
|
|
|
|
=={{header|F_Sharp|F#}}== |
|
=={{header|F_Sharp|F#}}== |