@echo off&&setlocal ENABLEDELAYEDEXPANSION for %%a in (1 2 3 4 5 6 7 8 9) do ( for %%b in (0 1 2 3 4 5 6 7 8 9) do ( for %%c in (0 1 2 3 4 5 6 7 8 9) do ( set/a result=%%a*%%a*%%a+%%b*%%b*%%b+%%c*%%c*%%c if "!result!"=="%%a%%b%%c" ( echo %%a%%b%%c是水仙花数! )
) ) ) pause
======================================================================================== 【02】by [lxmxn] ======================================================================================== ======================================================================================== 【03】by [youxi01] ======================================================================================== @echo off setlocal enabledelayedexpansion for /l %%i in (10 1 30) do ( ::清空变量 set flag= for /l %%a in (0 1 9) do set %%a= ::取得立方和四次方 set /a cube=%%i*%%i*%%i set /a s=!cube!*%%i if !cube! geq 1000 if !cube! lss 10000 ( if !s! geq 100000 if !s! lss 1000000 ( set num=!s!!cube! call :test !num! if not defined flag echo %%i !num! ) ) )
pause>nul :test for /l %%a in (0 1 9) do ( set var=%1 ::将参数的第一个数字赋值给var_;检查变量值!var_!是否已经被作为变量被定义。 set var_=!var:~%%a,1! if defined !var_! set flag=1 & goto :eof set !var_!=A )
@echo off set /a t_num=0 setlocal enabledelayedexpansion
echo 正在检测数据..... for /l %%i in (1 1 4889) do ( if !t_num! lss 4889 ( if %%i lss 10 set /a t_num+=1 if %%i geq 10 if %%i lss 100 set /a t_num+=2 if %%i geq 100 if %%i lss 1000 set /a t_num+=3 if %%i geq 1000 set /a t_num+=4 ) else set /a num=%%i-1 & goto :exit ) :exit echo 要求的数为:%num% pause>nul
setlocal enabledelayedexpansion for /l %%i in (1 1 %J_num%) do ( set /a S_num=%%i set /a B_num=%J_num%-%%i set /a num=!S_num!+2*!B_num! call :test !num! !S_num! !B_num! ) pause>nul
:test if %1 EQU %F_num% echo 可能的组合为:单峰数目=%2 双峰数目=%3 goto :eof
@echo off & echo 正在检测数据... setlocal enabledelayedexpansion for /l %%a in (0 1 9) do ( for /l %%b in (0 1 9) do ( for /l %%c in (0 1 9) do ( set/a Fnum=2%%a%%b%%c5 set Bnum=!Fnum:5=A! set Bnum=!Bnum:2=5! set/a Bnum=!Bnum:A=2! set/a Fnum_=2*!Fnum!+2 if !Bnum! EQU !Fnum_! echo !Fnum! ))) echo 检测完毕! pause>nul
::说明:该程序在XP pro sp2下测试通过。 ::解决这个问题,首先我们要明确这个数字结尾必须是5,因为只有这样,才可以在转化后才是偶数,才可以被2整除;而且首位数字必须是::2......
@echo off echo 正在检测数据.... setlocal enabledelayedexpansion for /l %%i in (1 1 10000) do ( set /a flag=0 set /a num=5*%%i+10 set /a num1=!num!%%4 set /a num2=!num!%%5 set /a num3=!num!%%6 for %%a in (!num1! !num2! !num3!) do ( if %%a NEQ 0 set /a flag=1 ) if !flag! EQU 0 set /a num=%%i & goto :exit ) :exit for /l %%i in (0 1 4) do ( set /a num%%i=%num%+%%i ) echo 要求的连续的5个自然数为:%num0% %num1% %num2% %num3% %num4% pause>nul
@echo off rem 经推算,首位数字必须为1,(除非未知数为1,为1的情况在第一个for中也处理了) setlocal enabledelayedexpansion for /l %%i in (0 1 9) do ( set /a Fnum=1%%i3 set /a Bnum=3%%i4 set /a num=!Bnum!/2-9 if !Fnum! EQU !num! echo !Fnum!)
for /l %%i in (0 1 9) do ( set /a Fnum=13%%i set /a Bnum=34%%i set /a num=!Bnum!/2-9 if !Fnum! EQU !num! echo !Fnum!) pause>nul
setlocal enabledelayedexpansion for /l %%i in (76 1 10000) do ( set /a Fnum=%%i*20-75*20 set /a Bnum=%%i*15+100*15 if !Fnum! EQU !Bnum! echo 小鸡的只数为:%%i & goto :exit) :exit pause>nul
@echo off echo 正在检测数据........ setlocal enabledelayedexpansion set /a flag=0 for /l %%i in (10000,1,99999) do ( set num=%%i rem 前面加个1是为了防止类似30820的特殊情况。 set /a num=1!num:3=! if !num! lss 2000 if !num! gtr 200 set /a flag+=1) echo %flag% echo 检测完毕! pause>nul
@echo off setlocal enabledelayedexpansion set num=17 set /a Cnum=%num%/3 set /a Rnum=%num%%%2 set /a Tnum=0 for /l %%i in (%Rnum% 2 %Cnum%) do ( set num_=1 set /a num_tem=%num%/2-%%i*3/2 for /l %%a in (1 1 %%i) do ( set /a num_*=3) for /l %%b in (1 1 !num_tem!) do ( set /a num_*=2) if !num_! gtr !Tnum! set /a Tnum=!num_! ) echo !Tnum! pause>nul
@echo off echo 正在检测数据........ setlocal enabledelayedexpansion set /a num=1 set /a flag=0 for /l %%i in (2 1 10000) do ( call :test %%i echo %%i !flag!)
:test set /a num=!num!*%1 for /l %%i in (1 1 5) do ( if !num:~-1! EQU 0 (set /a flag+=1 & set /a num=!num:~0,-1!) else ( set /a num=!num:~-1! & goto :eof))
@echo off echo 正在检测数据........ setlocal enabledelayedexpansion
for /l %%a in (90 1 180) do ( for /l %%b in (1 1 %%a) do ( set /a num=%%a %% %%b if !num! EQU 0 ( set /a num=%%a/%%b set /a num_=!num!+%%a+%%b if !num_! EQU 181 echo 这样的数有,被除数:%%a 除数:%%b 商:!num! ) ) ) echo. echo 检测完毕! pause>nul