Jump to content

Odd squarefree semiprimes: Difference between revisions

no edit summary
(Realize in F#)
No edit summary
Line 365:
Count: 194
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
 
function IsPrime(N: int64): boolean;
{Fast, optimised prime test}
var I,Stop: int64;
begin
if (N = 2) or (N=3) then Result:=true
else if (n <= 1) or ((n mod 2) = 0) or ((n mod 3) = 0) then Result:= false
else
begin
I:=5;
Stop:=Trunc(sqrt(N+0.0));
Result:=False;
while I<=Stop do
begin
if ((N mod I) = 0) or ((N mod (I + 2)) = 0) then exit;
Inc(I,6);
end;
Result:=True;
end;
end;
 
 
function CustomSort (Item1, Item2: Pointer): Integer;
begin
Result:=integer(Item1)-integer(Item2);
end;
 
 
procedure OddSquareFreeSemiprimes(Memo: TMemo);
var P,Q,I: integer;
const Limit = 1000;
var LS: TList;
var S: string;
begin
LS:=TList.Create;
try
P:=1;
{Test all relevant combinations of P and Q}
for P:=1 to Limit div 5 do
begin
if ((P and 1)=0) or (not IsPrime(P)) then continue;
for Q:=P+2 to Limit div P do
begin
if ((Q and 1)=0) or (not IsPrime(Q)) then continue;
{Put in list}
LS.Add(Pointer(P*Q))
end;
end;
{List is not in order, so sort it}
LS.Sort(CustomSort);
S:='';
for I:=0 to LS.Count-1 do
begin
S:=S+Format('%8D',[Integer(LS[I])]);
If (I mod 5)=4 then S:=S+CRLF;
end;
Memo.Lines.Add(S);
Memo.Lines.Add('Count='+IntToStr(LS.Count));
finally LS.Free; end;
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
15 21 33 35 39
51 55 57 65 69
77 85 87 91 93
95 111 115 119 123
129 133 141 143 145
155 159 161 177 183
185 187 201 203 205
209 213 215 217 219
221 235 237 247 249
253 259 265 267 287
291 295 299 301 303
305 309 319 321 323
327 329 335 339 341
355 365 371 377 381
391 393 395 403 407
411 413 415 417 427
437 445 447 451 453
469 471 473 481 485
489 493 497 501 505
511 515 517 519 527
533 535 537 543 545
551 553 559 565 573
579 581 583 589 591
597 611 623 629 633
635 649 655 667 669
671 679 681 685 687
689 695 697 699 703
707 713 717 721 723
731 737 745 749 753
755 763 767 771 779
781 785 789 791 793
799 803 807 813 815
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
Count=194
Elapsed Time: 9.048 ms.
 
</pre>
 
 
=={{header|F_Sharp|F#}}==
465

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.