#序号 !解决 ?未解决
#01 !(代码由lxmxn提供)
求水仙花数?
@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
类似题型:求勾股数?(代码由namejm提供)
@echo off
echo.
echo 100以内的勾股数如下:
echo.
setlocal enabledelayedexpansion
for /l %%i in (1,1,100) do (
for /l %%j in (1,1,100) do (
for /l %%k in (1,1,100) do (
set /a a=%%i*%%i
set /a b=%%j*%%j
set /a c=%%k*%%k
set /a sum=!a!+!b!
if !sum! equ !c! echo %%i %%j %%k
)
)
)
pause
#02 !(代码由zouzhxi提供)
有四个数,其中任意三个数相加,所得的和分别是84,88,99,110,求这四个数?
@ECHO OFF
echo.
setlocal enabledelayedexpansion
SET A=84
SET B=88
SET C=99
SET D=110
SET /A ABCD=A+B+C+D
SET /A SUM=ABCD/3
SET /A NO1=SUM-A
SET /A NO2=SUM-B
SET /A NO3=SUM-C
SET /A NO4=SUM-D
ECHO.
ECHO.NO1^=%NO1%
ECHO.NO2^=%NO2%
ECHO.NO3^=%NO3%
ECHO.NO4^=%NO4%
PAUSE
#03 !
赵姑娘的岁数有以下特点:
1. 它的3次方是一个四位数,而4次方是一个六位数;
2. 这四位数和六位数正好是0到9这十个数字组成.
问,这个数应该是什么数?
【解题思路】
取一个未知数,首先分别取得该数的立方和四次方;然后将这十个数字分别分割并都定义,最后检测从0~9是否都已经被定义,如果都被定义了,则该数满足要求,否则有重复数字,不满足要求。
@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
)
#04 !
排一本辞典的页码共用了4889个数字。这本辞典共有多少页? 答案:1499
【解题思路】
以下这个办法比较直接,直接检测数字的大小,如果小于10则为1位数字,10~99两位,....然后把所以的位数加起来即可。
@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
#05 !
阿聪说他这次去西北看见一群骆驼,共有23个驼峰,60只脚。请问单、双峰骆驼各多少只?
【解题思路】
首先从骆驼的脚的只数确定骆驼总的数目(除以4),然后依次检测从1到15间时候有符合题目的数据;
@echo off
set /a F_num=23
set /a J_num=60/4
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
#06 !
有一个五位奇数,将这个五位奇数中的所有2都换成5,所有5也都换成2,其他数保持不变,得到一个新的五位数,若新五位数的一半仍比原五位数大1,那么原五位数是多少?
【解题思路】
要明确的思路是:这个特殊的数字,首位必须为2,末尾必须为5(因为原来为奇数,但后来却可以有“一半”,说明是偶数,所以可以肯定,末尾是5,后来被替换成了2。
@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
#07 !
五个连续自然数的和分别能被2、3、4、5、6整除,求满足此条件的最小的一组数。
【解题思路】
没有什么技巧性。利用等差数列公式,先算出5个数字的总和,然后检测看它是不是能被4、5、6整除。
@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
#08 !
我是个三位数,其中有一个数字是“3”,还有一个数字是“1”,另一个数字是未知数。如果把“3”变成“4”、把“1”变成“3”,那么,原来的我将比假设后的我的一半还少“9”。你知道原来是个什么数?
【解题思路】
利用反证法可以知道,首位数字必须为1,所以该数的排列情况就可能为:1*3或者13*,然后去检测。
@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
#09 !
农夫琼斯对他老婆说:"喂,玛丽亚,如果照我的办法,卖掉75只小鸡,那么咱们的鸡饲料还能维持20夭。然而,假使照你的建议,再买进100只小鸡的话,那么鸡饲料将只够维持15天。"
"啊,亲爱的,"她答道,"那我们现在有多少只小鸡呢?"
问题就在这里了,他们究竟有多少只小鸡?
【解题思路】
整个过程中,小鸡吃的饲料是不变的。假设有X只鸡,则应该有:(x-75)*20=(x+100)*15,然后写一个循环,看哪个数字合适?!
@echo off
rem 小鸡的只数至少有76只:
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
#10 !
在所有的5位数当中,只包含两个3的数字有多少个?
【解题思路】
以下这个思路比较新颖。它的原理是:将数字中的3全部替换为空,检测方法举例说明:
如:75332 它被替换后变成752,变成了4位数以内的数字,只要检测它的大小就可以达到题目的要求。
@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
#11 !
将17分成几个自然数的和,求这几个自然数的最大乘积是多少?
【解题思路】
利用高中的数学知识可以证明,凡是大于等于4的数,它都可以拆成这样的两个数:它们的和与该数相等,乘积要大于等于该数。根据这样的推论,所有的数最后都会拆成这样的形式:A*A*A*A....A为2或者3(因为只有2和3不能拆了,最后剩下的肯定只有2和3)。
举例说明:8可以这样拆(没有3):
num1=2*2*2*2 也可以拆成(含有2个3):num2=2*3*3,然后只要比较两个num的大小就行了!
@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
#12 !
将自然数2、3......乘到一起,它们的积的最后6位数恰好都是0,最后一个自然数最少可能是几?
@echo off
echo 正在检测数据........
setlocal enabledelayedexpansion
set /a num=1
set /a flag=0
for /l %%i in (2 1 10000) do (
call :test %%i
if !flag! equ 5 set /a num=%%i & goto :exit)
:exit
echo.
echo 最小的自然数为:!num!
echo.
echo 检测完毕!
pause>nul
: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))
#13 !
被除数、除数和商三个数的和是181,商是12,求被除数。
@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
#14 !
商店里有六箱货物,分别重15、16、18、19、20、31千克,两个顾客买走了其中五箱.已知一个顾客买的货物重量是另一个顾客的2倍,那么,商店剩下的一箱货物重量是多少千克?
【解题思路】
可以很快的推断出的一个已知条件为:那两个顾客买走的两袋货物总质量可以被3整除,另一个顾客的可以被2整除.......
@echo off
set /a num=15+16+18+19+20+31
set Tnum=15 16 18 19 20 31
setlocal enabledelayedexpansion
rem ==========================
rem 第十四题:
for %%i in (15 16 18 19 20 31) do call :test %%i
echo 剩下的一包质量为:!result1!
echo 质量比较少的两包质量为:!result2! !result3!
pause>nul
:test
set /a num_tmp=%num%-%1
set /a Rnum=!num_tmp! %% 3
if !Rnum! NEQ 0 goto :eof
set Tnum_=!Tnum:%1 =!
set /a Snum=!num_tmp!/3
for %%a in (!Tnum_!) do (
set /a Rt=!Snum!-%%a
echo !Tnum_! | find "!Rt!" >nul 2>nul && (
set result3=%%a
set /a result2=!Rt!
set /a result1=%1))
#15 !
一个数除以3的余数是2,除以5的余数是1,则这个数除以15的余数是多少?
@echo off
setlocal enabledelayedexpansion
echo 在1~10000内,这样的数字以及除以15的余数分别为:
for /l %%i in (1 1 10000) do (
set /a num1=%%i %% 3
set /a num2=%%i %% 5
if !num1! EQU 2 if !num2! EQU 1 (
set /a Result=%%i
set /a num=!Result! %% 15
echo 数字:!Result! 余数:!num!
)
)
pause>nul
#16 !
1. p是质数,且p×p+1也是质数。求2006×p。
2. 2006个2的乘积除以7的余数是多少。
【解题思路】
1> PxP+1是质数,所以PxP+1是奇数(2除外),则P×P为偶数,则P一定为偶数,则P=2
2> 可以将2^2006写成这样的形式:2^2006=8^668×2×2=(7+1)^668×4,再根据排列组合公式可知,2^2006除以7的余数为:4
@echo off
setlocal enabledelayedexpansion
for %%i in (2 3 5 6 7 9 10 15 17 31 33 63 65) do (
set /a tmp=1
set /a Res=1
call :test %%i
echo 2^^^^2006除以%%i的余数为:!Res!)
pause>nul
::处理偶数
:test
if %1 GTR 2 (
set /a var=%1 %% 2
if !var! EQU 0 (
set /a num=%1/2
call :test !num!) else call :test1 %1) else set Res=0
goto :eof
:test1
for /l %%i in (1 1 10) do (
set /a tmp*=2
set /a Rnum=%1 %% 4
if !tmp! GEQ %1 (
if !Rnum! EQU 3 (
set /a Inum=%%i
set /a Inum_=2006 %% !Inum!
for /l %%a in (0 1 !Inum_!) do set /a Res*=2
set /a Res=!Res!/2
goto :eof)
set /a Inum=%%i-1
set /a Inum_=2006 %% !Inum!
for /l %%a in (0 1 !Inum_!) do set /a Res*=2
set /a Res=%1-!Res!/2
goto :eof
))
#17 !
传说在印度的一个圣庙里安放着一个黄铜板,板上插着三根宝石针,在第一根宝石针上,从下到上依次穿着从大到小的64片中心有孔的金片,圣庙里的僧人按下面规则移动金片:每次只能移动一片,而且小片永远要放在大片的上面。当时传说,当64片金片都移动到另一根宝石针上的时候,世界将在一声霹雳中毁灭。把64片金片移动到另一根宝石针上,需要移动多少次呢?这是一个非常大的数字!
答案:18446744073709551615
【解题思路】根据等比数列等相关知识,可知总共需要的次数为:2^64-1,这个数字极其庞大直接计算肯定是行不通的了,那只好采取 “曲线救国” 的办法。我把我采用的办法叫做 “钟表式分段计算法”,如果不是原创,请恕我卤莽!
以下代码是将数据分成了6段,每段6位数字来分别保存。它的基本原理是:当最后一段数据在乘以2以后,如果它的值大于1000000,则进位,将进位的数据加到前一段数据上,依次类推。该段代码目前支持200个2连续相乘,当然你可以“改装”,可以计算更庞大的数字。
@echo off
setlocal enabledelayedexpansion
::初始化每段数据;
for /l %%i in (1 1 5) do set /a num%%i=0
set /a num6=1
for /l %%i in (1 1 64) do (
rem ================================================
rem 初始化 进位数据 和 分段数据的计算公式(就是乘以2)
for /l %%i in (1 1 5) do (
set /a num%%i_=0
set /a num%%i*=2)
set /a num6*=2
rem ================================================
for /l %%a in (6 -1 1) do (
rem 每段数据保存一个6位数;
if !num%%a! GTR 1000000 (
set /a Inum=%%a-1
set /a tmp=!num%%a!
rem ========================================================================
rem 前面这个1是从前面的数据段“借”来的;前面加个1是为了防止set /a test=0003
rem 类似情况的出现!
set /a num%%a=1!tmp:~-6!
rem ========================================================================
rem 前面一段的数据加上后面一段数据的进位数再减1,因为有个1被“借”掉了!
set /a num!Inum!+=!tmp:~0,-6!-1
)
)
)
set /a num6-=1
rem ===================================================================
rem 扫尾工作,因为前面为了除错,采用了“借”数据的办法,下面就给它还原!
for /l %%a in (6 -1 4) do (
set /a Inum=%%a-1
set /a tmp=!num%%a!
set num%%a=!tmp:~1!
set /a num!Inum!+=!tmp:~0,1!)
rem ===================================================================
for %%i in (%num1% %num2% %num3% %num4% %num5% %num6%) do (
if %%i neq 0 set Result=!Result!%%i)
echo !Result!
pause>nul
#18 !
有十张币值分别为1分、2分、5分、1角、2角、5角、1元、2元、5元、10元的人民币,能组成多少种不同的币值?
【解题思路】根据排列组合的相关知识,知道总共的组合可能有:num=C(10,1)+C(10,2)+..+C(10,10)
@echo off
setlocal enabledelayedexpansion
set /a num=1
set /a Result=0
for /l %%i in (1 1 10) do (
call :test %%i 10
set /a Result+=!num! & set /a num=1)
echo 币值种类有:!Result!
pause>nul
::求C(n,r);
:test start_num end_num
set /a tmp=%2-%1+1
for /l %%i in (%tmp% 1 %2) do set /a num*=%%i
for /l %%i in (1 1 %1) do set /a num/=%%i
#Serial Number !Solved ?Unsolved
#01 !(Code provided by lxmxn)
Find narcissistic numbers?
@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 is a narcissistic number!
)
)
)
)
pause
Similar type of problem: Find Pythagorean triples? (Code provided by namejm)
@echo off
echo.
echo Pythagorean triples within 100 are as follows:
echo.
setlocal enabledelayedexpansion
for /l %%i in (1,1,100) do (
for /l %%j in (1,1,100) do (
for /l %%k in (1,1,100) do (
set /a a=%%i*%%i
set /a b=%%j*%%j
set /a c=%%k*%%k
set /a sum=!a!+!b!
if !sum! equ !c! echo %%i %%j %%k
)
)
)
pause
#02 !(Code provided by zouzhxi)
There are four numbers. When any three numbers are added together, the resulting sums are 84, 88, 99, and 110 respectively. Find these four numbers?
@ECHO OFF
echo.
setlocal enabledelayedexpansion
SET A=84
SET B=88
SET C=99
SET D=110
SET /A ABCD=A+B+C+D
SET /A SUM=ABCD/3
SET /A NO1=SUM-A
SET /A NO2=SUM-B
SET /A NO3=SUM-C
SET /A NO4=SUM-D
ECHO.
ECHO.NO1^=%NO1%
ECHO.NO2^=%NO2%
ECHO.NO3^=%NO3%
ECHO.NO4^=%NO4%
PAUSE
#03 !
Miss Zhao's age has the following characteristics:
1. Its cube is a four-digit number, and its fourth power is a six-digit number;
2. These four-digit number and six-digit number are exactly composed of the ten digits from 0 to 9.
Ask, what number should this be?
【Problem-solving idea】
Take an unknown number, first obtain the cube and fourth power of this number respectively; then divide the ten digits respectively and define them, and finally check whether all from 0 to 9 have been defined. If all have been defined, then this number meets the requirements; otherwise, there are repeated digits and it does not meet the requirements.
@echo off
setlocal enabledelayedexpansion
for /l %%i in (10 1 30) do (
::Clear variables
set flag=
for /l %%a in (0 1 9) do set %%a=
::Obtain cube and fourth power
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
::Assign the first digit of the parameter to var_; check whether the variable value !var_! has been defined as a variable.
set var_=!var:~%%a,1!
if defined !var_! set flag=1 & goto :eof
set !var_!=A
)
#04 !
A total of 4889 digits were used to number the pages of a dictionary. How many pages does this dictionary have? Answer: 1499
【Problem-solving idea】
The following method is relatively direct. Directly check the size of the number. If it is less than 10, it is a 1-digit number, 10~99 is 2 digits,.... Then add up all the digits.
@echo off
set /a t_num=0
setlocal enabledelayedexpansion
echo Checking data.....
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 The required number is: %num%
pause>nul
#05 !
Ah Cong said that he saw a group of camels in the northwest this time. There are 23 humps and 60 feet. How many single-humped and double-humped camels are there respectively?
【Problem-solving idea】
First determine the total number of camels from the number of feet of camels (divided by 4), and then successively check between 1 and 15 for data that meets the requirements;
@echo off
set /a F_num=23
set /a J_num=60/4
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 Possible combination: Number of single-humped camels=%2 Number of double-humped camels=%3
goto :eof
#06 !
There is a five-digit odd number. Replace all 2s with 5s and all 5s with 2s in this five-digit odd number, and other numbers remain unchanged, to get a new five-digit number. If half of the new five-digit number is still 1 larger than the original five-digit number, what is the original five-digit number?
【Problem-solving idea】
The clear idea is: the first digit must be 2, and the last digit must be 5 (because it was originally odd, but later can have "half", indicating it is even, so it can be determined that the last digit is 5, which was later replaced with 2.
@echo off & echo Checking data...
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 Checking completed!
pause>nul
#07 !
The sum of five consecutive natural numbers can be divisible by 2, 3, 4, 5, and 6 respectively. Find the smallest set of numbers that meets this condition.
【Problem-solving idea】
There is no particular skill. Use the arithmetic sequence formula, first calculate the sum of 5 numbers, and then check whether it can be divisible by 4, 5, 6.
@echo off
echo Checking data....
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 The required five consecutive natural numbers are: %num0% %num1% %num2% %num3% %num4%
pause>nul
#08 !
I am a three-digit number. There is one digit that is "3", another digit is "1", and the other digit is unknown. If "3" is changed to "4" and "1" is changed to "3", then the original me will be 9 less than half of the assumed me. Do you know what the original number is?
【Problem-solving idea】
Using the method of proof by contradiction, it can be known that the first digit must be 1, so the arrangement of the number may be: 1*3 or 13*, and then check.
@echo off
rem After deduction, the first digit must be 1, (unless the unknown is 1, and the situation of 1 is also processed in the first 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
#09 !
Farmer Jones said to his wife: "Hey, Maria, if we sell 75 chicks according to my method, then our chicken feed can last for 20 days. However, if we follow your suggestion and buy 100 more chicks, then the chicken feed will only last for 15 days."
"Ah, dear," she replied, "then how many chicks do we have now?"
The problem is here. How many chicks do they have exactly?
【Problem-solving idea】
Throughout the process, the amount of feed the chicks eat is unchanged. Suppose there are X chicks, then there should be: (x-75)*20=(x+100)*15, and then write a loop to see which number is appropriate?!
@echo off
rem The number of chicks is at least 76:
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 The number of chicks is: %%i & goto :exit)
:exit
pause>nul
#10 !
Among all five-digit numbers, how many have exactly two 3s?
【Problem-solving idea】
The following idea is relatively novel. Its principle is: replace all 3s in the number with empty, and the detection method is illustrated by an example:
For example: 75332 becomes 752 after replacement, which is a number with less than 4 digits. Just check its size to meet the requirements of the question.
@echo off
echo Checking data........
setlocal enabledelayedexpansion
set /a flag=0
for /l %%i in (10000,1,99999) do (
set num=%%i
rem Adding a 1 in front is to prevent special cases like 30820.
set /a num=1!num:3=!
if !num! lss 2000 if !num! gtr 200 set /a flag+=1)
echo %flag%
echo Checking completed!
pause>nul
#11 !
Divide 17 into the sum of several natural numbers, and find the maximum product of these natural numbers?
【Problem-solving idea】
Using high school mathematics knowledge, it can be proved that any number greater than or equal to 4 can be split into two numbers: their sum is equal to the number, and the product is greater than or equal to the number. According to this inference, all numbers will eventually be split into such forms: A*A*A*A....A is 2 or 3 (because only 2 and 3 cannot be split, and the remaining must be only 2 and 3).
For example: 8 can be split like this (without 3):
num1=2*2*2*2 or can be split into (with 2 threes): num2=2*3*3, then just compare the sizes of the two nums!
@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
#12 !
Multiply natural numbers 2, 3...... together. The last 6 digits of their product are exactly all 0s. What is the minimum possible value of the last natural number?
@echo off
echo Checking data........
setlocal enabledelayedexpansion
set /a num=1
set /a flag=0
for /l %%i in (2 1 10000) do (
call :test %%i
if !flag! equ 5 set /a num=%%i & goto :exit)
:exit
echo.
echo The minimum natural number is:!num!
echo.
echo Checking completed!
pause>nul
: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))
#13 !
The sum of the dividend, divisor, and quotient is 181, and the quotient is 12. Find the dividend.
@echo off
echo Checking data........
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 Such numbers exist. Dividend: %%a Divisor: %%b Quotient:!num!
)
)
)
echo.
echo Checking completed!
pause>nul
#14 !
There are six boxes of goods in the store, weighing 15, 16, 18, 19, 20, and 31 kilograms respectively. Two customers bought five of them. It is known that the weight of the goods bought by one customer is twice that of the other customer. Then, what is the weight of the remaining box of goods in the store?
【Problem-solving idea】
A known condition that can be quickly inferred is: the total mass of the two bags of goods bought by the two customers can be divisible by 3, and the other customer's can be divisible by 2.......
@echo off
set /a num=15+16+18+19+20+31
set Tnum=15 16 18 19 20 31
setlocal enabledelayedexpansion
rem ==========================
rem Question 14:
for %%i in (15 16 18 19 20 31) do call :test %%i
echo The mass of the remaining bag is:!result1!
echo The masses of the two bags with less mass are:!result2! !result3!
pause>nul
:test
set /a num_tmp=%num%-%1
set /a Rnum=!num_tmp! %% 3
if !Rnum! NEQ 0 goto :eof
set Tnum_=!Tnum:%1 =!
set /a Snum=!num_tmp!/3
for %%a in (!Tnum_!) do (
set /a Rt=!Snum!-%%a
echo !Tnum_! | find "!Rt!" >nul 2>nul && (
set result3=%%a
set /a result2=!Rt!
set /a result1=%1))
#15 !
A number has a remainder of 2 when divided by 3 and a remainder of 1 when divided by 5. What is the remainder when this number is divided by 15?
@echo off
setlocal enabledelayedexpansion
echo Within 1~10000, such numbers and their remainders when divided by 15 are respectively:
for /l %%i in (1 1 10000) do (
set /a num1=%%i %% 3
set /a num2=%%i %% 5
if !num1! EQU 2 if !num2! EQU 1 (
set /a Result=%%i
set /a num=!Result! %% 15
echo Number:!Result! Remainder:!num!
)
)
pause>nul
#16 !
1. p is a prime number, and p×p+1 is also a prime number. Find 2006×p.
2. What is the remainder when the product of 2006 2s is divided by 7?
【Problem-solving idea】
1> PxP+1 is a prime number, so PxP+1 is odd (except 2), then P×P is even, so P must be even, then P=2
2> 2^2006 can be written in the form: 2^2006=8^668×2×2=(7+1)^668×4. According to the binomial theorem, the remainder of 2^2006 divided by 7 is: 4
@echo off
setlocal enabledelayedexpansion
for %%i in (2 3 5 6 7 9 10 15 17 31 33 63 65) do (
set /a tmp=1
set /a Res=1
call :test %%i
echo The remainder of 2^^^^2006 divided by %%i is:!Res!)
pause>nul
::Process even numbers
:test
if %1 GTR 2 (
set /a var=%1 %% 2
if !var! EQU 0 (
set /a num=%1/2
call :test !num!) else call :test1 %1) else set Res=0
goto :eof
:test1
for /l %%i in (1 1 10) do (
set /a tmp*=2
set /a Rnum=%1 %% 4
if !tmp! GEQ %1 (
if !Rnum! EQU 3 (
set /a Inum=%%i
set /a Inum_=2006 %% !Inum!
for /l %%a in (0 1 !Inum_!) do set /a Res*=2
set /a Res=!Res!/2
goto :eof)
set /a Inum=%%i-1
set /a Inum_=2006 %% !Inum!
for /l %%a in (0 1 !Inum_!) do set /a Res*=2
set /a Res=%1-!Res!/2
goto :eof
))
#17 !
It is said that in a holy temple in India, there is a brass plate with three gem needles inserted on it. On the first gem needle, from bottom to top, there are 64 golden plates with holes in the center, arranged from largest to smallest. The monks in the temple move the plates according to the following rules: only one plate can be moved at a time, and the small plate must always be placed on the large plate. At that time, it was said that when all 64 golden plates were moved to another gem needle, the world would be destroyed in a thunderclap. How many times does it take to move 64 golden plates to another gem needle? This is a very large number!
Answer: 18446744073709551615
【Problem-solving idea】According to relevant knowledge such as geometric sequences, it is known that the total number of times required is: 2^64-1. This number is extremely large, and direct calculation is definitely not feasible. Then we have to adopt the method of "segmented calculation in a clock-like manner". If it is not original, please forgive my rudeness!
The following code divides the data into 6 segments, each with 6 digits to save respectively. Its basic principle is: when the last segment of data is multiplied by 2, if its value is greater than 1000000, carry over, add the carried data to the previous segment of data, and so on. This segment of code currently supports the continuous multiplication of 200 2s. Of course, you can "modify" it to calculate more massive numbers.
@echo off
setlocal enabledelayedexpansion
::Initialize each segment of data;
for /l %%i in (1 1 5) do set /a num%%i=0
set /a num6=1
for /l %%i in (1 1 64) do (
rem ================================================
rem Initialize the carry data and the calculation formula of the segmented data (that is, multiply by 2)
for /l %%i in (1 1 5) do (
set /a num%%i_=0
set /a num%%i*=2)
set /a num6*=2
rem ================================================
for /l %%a in (6 -1 1) do (
rem Each segment of data saves a 6-digit number;
if !num%%a! GTR 1000000 (
set /a Inum=%%a-1
set /a tmp=!num%%a!
rem ========================================================================
rem The 1 in front is "borrowed" from the previous segment of data; adding a 1 in front is to prevent the occurrence of set /a test=0003
rem Similar situations!
set /a num%%a=1!tmp:~-6!
rem ========================================================================
rem The previous segment of data plus the carry of the current segment of data minus 1, because a 1 was "borrowed"!
set /a num!Inum!+=!tmp:~0,-6!-1
)
)
)
set /a num6-=1
rem ===================================================================
rem Tailoring work, because the previous step used the method of "borrowing" data for debugging, and now restore it!
for /l %%a in (6 -1 4) do (
set /a Inum=%%a-1
set /a tmp=!num%%a!
set num%%a=!tmp:~1!
set /a num!Inum!+=!tmp:~0,1!)
rem ===================================================================
for %%i in (%num1% %num2% %num3% %num4% %num5% %num6%) do (
if %%i neq 0 set Result=!Result!%%i)
echo !Result!
pause>nul
#18 !
There are ten RMB notes with denominations of 1 cent, 2 cents, 5 cents, 1 jiao, 2 jiao, 5 jiao, 1 yuan, 2 yuan, 5 yuan, and 10 yuan. How many different denominations can be formed?
【Problem-solving idea】According to the relevant knowledge of permutations and combinations, it is known that the total number of combinations may be: num=C(10,1)+C(10,2)+..+C(10,10)
@echo off
setlocal enabledelayedexpansion
set /a num=1
set /a Result=0
for /l %%i in (1 1 10) do (
call :test %%i 10
set /a Result+=!num! & set /a num=1)
echo The number of denominations is:!Result!
pause>nul
::Find C(n,r);
:test start_num end_num
set /a tmp=%2-%1+1
for /l %%i in (%tmp% 1 %2) do set /a num*=%%i
for /l %%i in (1 1 %1) do set /a num/=%%i