Semiprime: Difference between revisions

(→‎{{header|Python}}: Python 2.x/3.x compatability)
Line 2:
 
Write a function determining whether a given number is semiprime.
 
=={{header|Ada}}==
 
This imports the package '''Prime_Numbers''' from [[Prime decomposition#Ada]].
 
<lang ada>with Prime_Numbers, Ada.Text_IO;
procedure Test_Semiprime is
package Integer_Numbers is new
Prime_Numbers (Natural, 0, 1, 2);
use Integer_Numbers;
begin
for N in 1 .. 100 loop
if Decompose(N)'Length = 2 then -- N is a semiprime;
Ada.Text_IO.Put(Integer'Image(Integer(N)));
end if;
end loop;
Ada.Text_IO.New_Line;
for N in 1675 .. 1680 loop
if Decompose(N)'Length = 2 then -- N is a semiprime;
Ada.Text_IO.Put(Integer'Image(Integer(N)));
end if;
end loop;
end Test_Semiprime;</lang>
 
It outputs all semiprimes below 100 and all semiprimes between 1675 and 1680:
{{output}}
4 6 9 10 14 15 21 22 25 26 33 34 35 38 39 46 49 51 55 57 58 62 65 69 74 77 82 85 86 87 91 93 94 95
1678 1679
 
Note that
1675 = 5 * 5 * 67,
1676 = 2 * 2 * 419,
1677 = 3 * 13 * 43,
1678 = 2 * 839,
1679 = 23 * 73,
1680 = 2 * 2 * 2 * 2 * 3 * 5 * 7,
so the result printed is actually correct.
 
 
 
=={{header|C}}==
Anonymous user