- @ECHO OFF
- SETLOCAL ENABLEDELAYEDEXPANSION
-
- ::生成素数相关变量,适用于数量较少的情况;数量多时可以生成临时文件
- SET _2=#
- FOR /L %%N IN (3,2,100)DO (
- SET/aMAX=%%N-2
- SET MFLAG=
- FOR /L %%S IN (3,2,!MAX!)DO (
- SET/aMOD=%%N%%%%S
- IF !MOD!==0 SET MFLAG=1
- )
- IF NOT DEFINED MFLAG SET _%%N=#
- )
-
- ::显示所有素数
- FOR /L %%N IN (2,1,100)DO IF DEFINED _%%N ECHO,%%N
-
- ECHO,
- ECHO,输出满足条件的素数:
- ::判断
- FOR /L %%N IN (2,1,100)DO (
- SET/a@4=%%N+4,@A4=@4%%5,@A2=%%N+2,@B4=%%N-4
- FOR /F "TOKENS=1,2" %%F IN ("!@A2! !@B4!")DO (
- IF !_%%N!_!@A4!_!_%%F!_!_%%G!==#_0_#_# ECHO,%%N
- )
- )
- PAUSE
复制代码
|