@echo off if "%1"=="" goto usage setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS set n=%1 for /l %%i in (2,1,%n%) do set l%%i=1 for /l %%i in (2,1,%n%) do if DEFINED l%%i call :sieve %%i for /l %%i in (2,1,%n%) do if DEFINED l%%i echo %%i endlocal goto :EOF :usage echo %~nx0 - Sieve of Eratosthenes echo. echo Usage echo %~nx0 n echo. echo n - maximum number to test for primality goto :EOF :sieve set /a begin=%1 set /a max=%n% / %1 for /l %%k in (%begin%,1,%max%) do set /a foo=%1 * %%k && set l!foo!= goto :EOF