一种方法吧,不见得速度快。- @echo off&setlocal EnableDelayedExpansion
- set "th=1"&set /p=请输入一个数:
- for /l %%i in (1,1,!p!) do (
- set "str=!str!1"
- )
- rem 也可以加上先判断是否偶数。
- for /l %%i in (3,2,!p!) do (
- set "th=!th!11"
- for /f %%j in ("!th!") do (
- if "!str:%%j=!"=="" set "flag=非素"&goto :end
- )
- )
- :end
- if defined flag (
- echo 非素数
- ) else (
- echo 素数
- )
复制代码
|