本帖最后由 applba 于 2011-4-27 13:24 编辑
既然上面求了极大值,现在就不存在溢出问题了: | @echo off &setlocal enabledelayedexpansion | | :input | | cls | | set /p _n=请输入正整数: | | set /a n=!_n!&&if !n! lss 2 goto input | | set /a "varup=1,vardn=2147483647" | | for /l %%i in (1,1,30) do ( | | set /a "varup=!varup!*!n!,vardn=!vardn!/!n!" | | set /a "var=!vardn!/!varup!" | | if !var! lss !n! ( | | if !var! equ 0 (set /a "cnt=2*%%i-1" && goto out) | | set /a "cnt=2*%%i" && goto out | | ) | | ) | | :out | | echo !n!的!cnt!次方接近最大值! | | PAUSE&goto inputCOPY |
思路也很简单,正反一起用,往中间碰撞…… |