Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Twin-primes/XPL0/twin-primes.xpl0
Normal file
29
Task/Twin-primes/XPL0/twin-primes.xpl0
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
func IsPrime(N); \Return 'true' if N is prime
|
||||
int N, I;
|
||||
[if N <= 2 then return N = 2;
|
||||
if (N&1) = 0 then \even >2\ return false;
|
||||
for I:= 3 to sqrt(N) do
|
||||
[if rem(N/I) = 0 then return false;
|
||||
I:= I+1;
|
||||
];
|
||||
return true;
|
||||
];
|
||||
|
||||
func Twins(Limit);
|
||||
int Limit, C, N;
|
||||
[C:= 0; N:= 3;
|
||||
repeat if IsPrime(N) then
|
||||
loop [N:= N+2;
|
||||
if N >= Limit then return C;
|
||||
if not IsPrime(N) then quit;
|
||||
C:= C+1;
|
||||
];
|
||||
N:= N+2;
|
||||
until N >= Limit;
|
||||
return C;
|
||||
];
|
||||
|
||||
[IntOut(0, Twins(100_000)); CrLf(0);
|
||||
IntOut(0, Twins(10_000_000)); CrLf(0);
|
||||
IntOut(0, Twins(100_000_000)); CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue