Criba de Eratostenes

Iniciado por binary_death, Septiembre 03, 2013, 05:52:07 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Código: php
@Echo Off
SetLocal EnableDelayedExpansion
Title Criba de Eratostenes
::Coded By Binary_Death
Set/P "Utl=Until >> "
:_Main
Set/A "ActN=1"
For /l %%z in (2,1,%Utl%) do (
  Set "Lst=!Lst! %%z"
)
:_LoopA
For /f "Tokens=%ActN% Delims= " %%n in ("%Lst%") do (
    Set/A "Qrd=%%n*%%n"
If !Qrd! GTR %Utl% GoTo:_EndA
   For %%l in (%Lst%) Do (
     Set/A "Rst=%%l%%%%n"
        If %%l EQU %%n Set/A "Rst=1"
        If !Rst! NEQ 0 Set "NLst=!NLst! %%l"
    )
   Set "Lst=!NLst!" & Set "NLst=" & Set/A "ActN+=1"
)
Goto:_LoopA
:_EndA
Echo.&Echo.%Lst%
Pause > NUL
Exit


Un simple algoritmo que permite obtener los números primos hasta el especificado.