Jump to content

Odd squarefree semiprimes: Difference between revisions

m
→‎{{header|Ring}}: removed formatting kludge, added function call to primitive string formatter
m (C# - Edited code & output to reflect new task name)
m (→‎{{header|Ring}}: removed formatting kludge, added function call to primitive string formatter)
Line 348:
<lang ring>? "working..." + nl + "Odd squarefree semiprimes are:"
limit = 1000 Prim = []
Prim = []
 
# table of prime numbers from 3 to 1000/3
pr = [ 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
3779, 4183, 4389, 4797, 101, 53103, 107, 59109, 113, 61127, 131, 67137, 139, 71149, 151, 157, 163, 167, 173, 73179,
181, 79191, 193, 83197, 199, 89211, 223, 227, 229, 233, 239, 241, 251, 97257, 101263, 103269, 107271, 109277, 113281, 127283,
131, 137, 139, 149, 151, 157, 163, 167, 173, 179,
181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
239, 241, 251, 257, 263, 269, 271, 277, 281, 283,
293, 307, 311, 313, 317, 331]
pl = len(pr)
 
# calculate upper limit for n
for nlim = 1 to pl
if pr[nlim] * pr[nlim] > limit exit ok
next nlim--
exit
ok
next
nlim--
 
# add items to result list and sort
for n = 1 to nlim
for m = n + 1 to pl
amt = pr[n] * pr[m]
if amt > limit exit ok
exit
ok
add(Prim, amt)
next
next Prim = sort(Prim)
next
Prim = sort(Prim)
 
# display results
for n = 1 to len(Prim)
ifsee sf(Prim[n], <4) 100+ " "
if n % 20 = 0 see "nl "ok
next n--
ok
 
see " " + Prim[n] + " "
? nl + nl + "Found " + n + " Odd squarefree semiprimes." + nl + "done..."</lang>
if n % 20 = 0
 
see nl
# a very plain string formatter, intended to even up columnar outputs
ok
def sf x, y
next
s = string(x) l = len(s)
n--
if l > y y = l exitok
? nl + "Found " + n + " Odd squarefree semiprimes." + nl + "done..."</lang>
return substr(" ", 11 - y + l) + s </lang>
{{out}}
<pre>working...
Line 406 ⟶ 397:
817 831 835 843 849 851 865 869 871 879 889 893 895 899 901 905 913 917 921 923
933 939 943 949 951 955 959 965 973 979 985 989 993 995
 
Found 194 Odd squarefree semiprimes.
done...</pre>
</pre>
 
=={{header|Wren}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.