『楼 主』:
[原创]*****筛选质数*****
@echo off
setlocal enabledelayedexpansion
::::::::::::::::::::::::::::Find Prime Numbers::::::::::::::::::::::::::::
::::::::::::::::::::::::::::{s11ss 2007-9-20}::::::::::::::::::::::::::::
:r
echo Please input the upper limit number:
set /p n=
if not !n! geq 2 (echo 2 at least. & goto :r)
set /a i=2
:ci
set /a j=!i!
:cj
set /a m=!i!*!j!
if !m! leq !n! (
set /a j+=1
::set /a counter+=1
set m!m!=1
goto :cj
) else (
set /a i+=1
set /a ii=!i!*!i!
if !ii! leq !n! (goto :ci) else (goto :e)
)
:e
set s=
for /l %%a in (2,1,!n!) do (
if !m%%a! equ 1 (
set s=%%a !s!
)
)
set /a counter=0
echo.
echo In [2,!n!],prime numbers are:
for /l %%a in (2,1,!n!) do (
set isprime=True
set prime=%%a
for %%b in (!s!) do (
if !prime! equ %%b set isprime=False
)
if !isprime! equ True (
echo !prime!
set /a counter+=1
)
)
echo.
echo In total:!counter!
echo.
echo Press Any Key To Exit.
pause>nul 修改提速版:
@echo off
setlocal enabledelayedexpansion
::::::::::::::::::::::::::::Find Prime Numbers::::::::::::::::::::::::::::
::::::::::::::::::::::::::::{s11ss 2007-9-20}::::::::::::::::::::::::::::
:r
echo Please input the upper limit number:
set /p n=
if not !n! geq 2 (echo 2 at least. & goto :r)
echo.
echo Calculating...
set /a i=2
for /l %%a in (2,1,!n!) do (
set m%%a=0
)
:ci
set /a j=!i!
:cj
set /a m=!i!*!j!
if !m! leq !n! (
set /a j+=1
set m!m!=1
goto :cj
) else (
set /a i+=1
set /a ii=!i!*!i!
if !ii! leq !n! (goto :ci) else (goto :e)
)
:e
set /a counter=0
echo.
echo In [2,!n!],prime numbers are:
for /l %%a in (2,1,!n!) do (
if !m%%a! equ 0 (
echo %%a
set /a counter+=1
)
)
echo.
echo In total:!counter!
echo.
echo Press Any Key To Exit.
pause>nul [ Last edited by s11ss on 2007-9-20 at 10:27 PM ]
|