Odd squarefree semiprimes: Difference between revisions

Content added Content deleted
(→‎{{header|ALGOL 68}}: Calculate a more sensible number of primes)
m (C# - Edited code & output to reflect new task name)
Line 63: Line 63:


=={{header|C#|CSharp}}==
=={{header|C#|CSharp}}==
This reveals a set of non-prime numbers with exactly two factors for each '''<big>''n''</big>''', where '''<big>''1 < p < q < n''</big>'''.
This reveals a set of semi-prime numbers (with exactly two factors for each '''<big>''n''</big>'''), where '''<big>''1 < p < q < n''</big>'''. It is square-free, since '''<big>''p < q''</big>'''.
<lang csharp>using System; using static System.Console; using System.Collections;
<lang csharp>using System; using static System.Console; using System.Collections;
using System.Linq; using System.Collections.Generic;
using System.Linq; using System.Collections.Generic;
Line 73: Line 73:
res.Add(amt = pr[p] * pr[q]); } res.Sort(); foreach(var item in res.TakeWhile(x => x < lmt))
res.Add(amt = pr[p] * pr[q]); } res.Sort(); foreach(var item in res.TakeWhile(x => x < lmt))
Write("{0,4} {1}", item, ++c % 20 == 0 ? "\n" : "");
Write("{0,4} {1}", item, ++c % 20 == 0 ? "\n" : "");
Write("\n\nCounted {0} special odd prime products under {1}", c, lmt); } }
Write("\n\nCounted {0} odd squarefree semiprimes under {1}", c, lmt); } }


class PG { public static IEnumerable<int> Primes(int lim) {
class PG { public static IEnumerable<int> Primes(int lim) {
Line 93: Line 93:
933 939 943 949 951 955 959 965 973 979 985 989 993 995
933 939 943 949 951 955 959 965 973 979 985 989 993 995


Counted 194 special odd prime products under 1000</pre>
Counted 194 odd squarefree semiprimes under 1000</pre>


=={{header|C++}}==
=={{header|C++}}==