China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 00:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Discussion][Exploration] Using batch processing to make interesting math problems DigestI View 36,425 Replies 139
Original Poster Posted 2006-11-12 08:20 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
1. Find narcissistic numbers. (A narcissistic number is a number where the sum of the cubes of its digits equals the number itself. For example, 153 = 1*1*1 + 5*5*5 + 3*3*3)
Solution: 4F

2. There are four numbers. When any three numbers are added together, the resulting sums are 84, 88, 99, 110 respectively. Find these four numbers.
Solution: 11F、

3. Miss Zhao's age has the following characteristics:
①. Its cube is a four-digit number, and its fourth power is a six-digit number;
②. The four-digit number and the six-digit number exactly use all the ten digits from 0 to 9.
Ask, what number should this be?
Solution: 12F


4. Arranging the page numbers of a dictionary uses a total of 4889 digits. How many pages does this dictionary have in total? Answer: 1499
Solution: 15F

5. Ah Cong said that he saw a group of camels in the northwest this time. There are 23 humps and 60 feet in total. Ask how many single-humped and double-humped camels there are respectively?
Solution: 15F

6. There is a five-digit odd number. Replace all 2s in this five-digit odd number with 5s and all 5s with 2s, and keep other numbers unchanged to get a new five-digit number. If half of the new five-digit number is still 1 greater than the original five-digit number, what is the original five-digit number?
Solution: 23F、26F

7. The sum of five consecutive natural numbers can be divisible by 2, 3, 4, 5, 6 respectively. Find the smallest group of numbers that meet this condition.
Solution: 24F

8. I am a three-digit number. There is a digit "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 one is?
Solution: 30F、

9. 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?"
Here is the problem. How many chicks do they have exactly?
Solution: 30F

10. Among all five-digit numbers, how many contain exactly two 3s?
Solution: 30F

11. Divide 17 into the sum of several natural numbers. Find the maximum product of these natural numbers.
Solution: 31F

12. Multiply natural numbers 2, 3... together. The last 6 digits of their product are exactly all 0s. What is the smallest possible last natural number?
Solution: 31F

13. The sum of the dividend, divisor and quotient is 181, and the quotient is 12. Find the dividend.
Solution: 31F

14. There are six boxes of goods in the store, weighing 15, 16, 18, 19, 20, 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?
Solution: 33F

15. A number leaves 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?
Solution: 35F

16.
①. p is a prime number, and p×p + 1 is also a prime number. Find 2006×p. Solution: None
②. What is the remainder when the product of 2006 2s is divided by 7? Solution: 40F

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 gold plates with holes in the center, getting smaller from bottom to top. The monks in the holy temple move the gold plates according to the following rules: only one plate can be moved each time, and the small plate must always be placed on the large plate. It was rumored at that time that when all 64 gold plates were moved to another gem needle, the world would be destroyed in a thunderclap. How many times does it take to move 64 gold plates to another gem needle? This is a very large number!
Answer: 18446744073709551615
Solution: 42F

18. There are ten banknotes with denominations of 1 cent, 2 cents, 5 cents, 1 jiao, 2 jiao, 5 jiao, 1 yuan, 2 yuan, 5 yuan, 10 yuan respectively. How many different denominations can be formed?
Solution: 43F

19. What is the number of even digits in the product of two ten-digit numbers 3333333333 and 9999999999? (Can it be done only with multiplication and subtraction?)
Solution: 65F

20. Three mutually meshing gears, namely gear A, gear B, and gear C. When gear A rotates 5 times, gear B rotates 7 times and gear C rotates 2 times. What should be the minimum number of teeth for each of these three gears respectively?
Solution: 66F

21. There are two basins of water, one cold and one hot. There is a thermometer in the cold water basin. Use a small cup to take a cup of hot water and pour it into the cold water. It is found that the temperature rises by 5 degrees. Then pour another cup of hot water in, and it rises by 3 degrees again. Ask, if you pour another cup in, how many degrees will it rise again? (This question is provided by NaturalJ0)
Solution: 76F

22. Find Pythagorean triples
Solution: 8F、9F

#23?
Weighing beads =
There are 243 beads that look exactly the same in appearance. One of them is a little heavier. With a balance without weights, what is the minimum number of weighings needed to find this bead?

#24?
The frog sitting in the well looking at the sky =
The frog sitting in the well one day suddenly got the whim to go out and see the world. The well is nine feet deep. The frog can only jump three feet high at a time. How many jumps does the frog need to make to jump out of the well?

#25?
How many chickens and dogs are there =
There are seventy-nine chicks and dogs. There are two hundred feet on the ground. Think about it and calculate, how many chickens are there? How many dogs are there?

#26?
How many big and small monks are there respectively =
This is an ancient arithmetic problem: One hundred monks and one hundred rice cakes. Each big monk eats four rice cakes, and four small monks eat one rice cake. How many big and small monks are there respectively?

#???
New question
http://www.cn-dos.net/forum/viewthread.php?tid=24951&pid=220052&page=9&sid=Y7sfAE#pid220052




——————————————Dividing line———————————————


***********************************
Version management log
***********************************
Operation: Essence of the topic
Executor: 3742668
Original reason: Thanks to zouzhxi and youxi01 and the friends downstairs for bringing such a wonderful post. The purpose of "learning together, progressing together" is vividly reflected in this post.
Explanation: Since there is no clear basis for essence currently, friends who have doubts about this operation can post a reply to point it out, or leave a message in the private message system.
***********************************


[ Last edited by zouzhxi on 2007-8-21 at 12:16 PM ]
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
redtek +5 2006-11-16 06:46
AlexZhang +2 2007-07-03 10:45
Attachments
用批处理作趣味数学题(问题加代码).txt (19.94 KiB, Credits to download 1 pts, Downloads: 122)
用批处理作趣味数学题(问题加代码).txt (20.16 KiB, Credits to download 1 pts, Downloads: 96)
Floor 2 Posted 2006-11-12 08:46 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
There are many numbers that conform to the Pythagorean theorem. Why do you say (that within 1,000,000,000,000 there is only one set like 5*5=3*3+4*4)? For example: 10*10=6*6+8*8, etc.

[ Last edited by 不得不爱 on 2006-11-11 at 08:59 PM ]
Floor 3 Posted 2006-11-12 08:59 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
Yes,
When running, I waited for half an hour,,,
The result is only this group, and the others are not equal...

For example: 6*6 ≠ 4*4 + 5*5
Floor 4 Posted 2006-11-12 09:45 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

Among three-digit integers, only 153, 370, 371, and 407 have the characteristics of narcissistic numbers.

Please test this code:

@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
Floor 5 Posted 2006-11-12 09:46 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
It turns out that batch processing algorithms are also so interesting

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 6 Posted 2006-11-12 11:49 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
lxmxn's code in 4F can be further streamlined. Replacing `for %%a` with a `for /l` counting loop can eliminate the need to list numbers.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 7 Posted 2006-11-12 12:12 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
4-digit numbers: 1634, 8208, 9474
5-digit numbers: 54748, 92727, 93084

^_^
Floor 8 Posted 2006-11-12 12:17 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
The algorithm for Pythagorean triples is as follows. Interestingly, when using the for /l counting loop, the speed of calculating narcissistic numbers is very fast, while the speed of calculating Pythagorean triples is very slow:

@echo off
echo.
echo The 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
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 9 Posted 2006-11-13 00:56 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
TO: Moderator of Floor 8: "The algorithm for Pythagorean triples is as follows. It's strange that when using a for /l counting loop, the speed of calculating narcissistic numbers is very fast, but the speed of calculating Pythagorean triples is very slow: Your amount of calculation is a thousand times that of the previous one, so of course the speed is much slower. You can make a slight modification to the code, which can not only eliminate duplicate terms (such as 3 4 5 and 4 3 5) but also greatly improve the running efficiency:



@echo off
echo.
echo The Pythagorean triples within 100 are as follows:
echo.
setlocal enabledelayedexpansion
for /l %%i in (1,1,100) do (
for /l %%j in (%%i,1,100) do (
for /l %%k in (%%j,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


[ Last edited by youxi01 on 2006-11-16 at 11:41 PM ]
Floor 10 Posted 2006-11-13 01:11 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Hehe, not considering to eliminate duplicate results indeed can greatly increase the amount of computation.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 11 Posted 2006-11-13 02:26 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
The Pythagorean triple I calculated is like this: 5*5 = 4*4 + 3*3, which is a group of consecutive numbers.



Another problem:
There are four numbers. When any three numbers are added together, the resulting sums are 84, 88, 99, 110 respectively. Find these four numbers?
My method is like this, write it out for you to see, don't laugh.

@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

Do you have any simpler methods!!!!





Another problem:


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. This four-digit number and six-digit number are exactly composed of the ten digits from 0 to 9.
Ask, what number should this be?


[ Last edited by zouzhxi on 2006-11-13 at 02:28 AM ]
Floor 12 Posted 2006-11-13 08:04 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
This little girl is 18 years old. Making a humble show:

@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=
::Get 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
)
Floor 13 Posted 2006-11-13 09:57 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Wow, impressive~
Floor 14 Posted 2006-11-13 10:06 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
Another one,


A dictionary used 4889 digits in total for numbering the pages. How many pages does this dictionary have?

Answer: 1499.


Acong said he saw a group of camels in the northwest this time, with 23 humps and 60 feet. How many single-humped and double-humped camels are there respectively?


Gotta go, going to eat... Hehe... Come back on Monday...

[ Last edited by zouzhxi on 2006-11-13 at 10:10 AM ]
Floor 15 Posted 2006-11-13 12:15 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
### Part One
@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

### Part Two
@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: single-peak number=%2 double-peak number=%3
goto :eof
1 2 3 10 Next ›
Forum Jump: