Safe primes and unsafe primes: Difference between revisions

Safe primes and unsafe primes en BASIC256
(Added XPL0 example.)
(Safe primes and unsafe primes en BASIC256)
Line 326:
Number below 10000000: 633922
</pre>
 
 
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<lang BASIC256>arraybase 1
max = 1000000
sc1 = 0: usc1 = 0: sc2 = 0: usc2 = 0
safeprimes$ =""
unsafeprimes$ = ""
 
redim criba(max)
# False = prime, True = no prime
criba[0] = True
criba[1] = True
 
for i = 4 to max step 2
criba[i] = 1
next i
for i = 3 to sqr(max) +1 step 2
if criba[i] = False then
for j = i * i to max step i * 2
criba[j] = True
next j
end if
next
 
usc1 = 1
unsafeprimes$ = "2"
for i = 3 to 3001 step 2
if criba[i] = False then
if criba[i \ 2] = False then
sc1 += 1
if sc1 <= 35 then safeprimes$ += " " + string(i)
else
usc1 += 1
if usc1 <= 40 then unsafeprimes$ += " " + string(i)
end if
end if
next i
 
for i = 3003 to max \ 10 step 2
if criba[i] = False then
if criba[i \ 2] = False then
sc1 += 1
else
usc1 += 1
end if
end if
next i
 
sc2 = sc1
usc2 = usc1
for i = max \ 10 + 1 to max step 2
if criba[i] = False then
if criba[i \ 2] = False then
sc2 += 1
else
usc2 += 1
end if
end if
next i
 
print "the first 35 Safeprimes are: "; safeprimes$
print
print "the first 40 Unsafeprimes are: "; unsafeprimes$
print
print " Safeprimes Unsafeprimes"
print " Below -------------------------"
print max \ 10, sc1, usc1
print max , sc2, usc2
end</lang>
 
 
=={{header|C}}==
2,148

edits