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-07-31 22:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Discussion][Exploration] Using batch processing to make interesting math problems DigestI View 36,409 Replies 139
Floor 16 Posted 2006-11-13 21:08 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Not bad. Have research on algorithms.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 17 Posted 2006-11-13 22:08 ·  中国 广东 广州 天河区 电信
中级用户
★★
Credits 259
Posts 112
Joined 2006-09-18 04:55
19-year member
UID 62928
Gender Male
Status Offline
Wow..In-depth...Learninging!!!
Floor 18 Posted 2006-11-15 00:26 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
To promote algorithm research, heh heh.


There is a five-digit odd number. Replace all 2s with 5s and all 5s with 2s in this five-digit odd number, while keeping other digits unchanged, to get a new five-digit number. If half of the new five-digit number is still 1 more than the original five-digit number, what is the original five-digit number?
Floor 19 Posted 2006-11-15 00:42 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Haha... Interesting~ :)
Can start a batch processing and data structure algorithm special section~ :)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 20 Posted 2006-11-15 02:25 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
The sum of five consecutive natural numbers can be divided by 2, 3, 4, 5, and 6 respectively. Find the smallest set of such numbers that meets the condition.
Floor 21 Posted 2006-11-15 03:56 ·  中国 上海 教育网
初级用户
Credits 52
Posts 27
Joined 2006-10-06 00:44
19-year member
UID 64647
From ☆逍遥宫☆
Status Offline
Not bad~~After seeing so many treatments~~I think the several treatments upstairs are quite beautiful~~worthy of everyone's joint research~~Thank you all~~~
Floor 22 Posted 2006-11-15 06:36 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
It is suggested that zouzhxi concentrate all issues in the top in the format of serial number + content listed. Once solved, make a mark or instruction behind this serial number, so that everyone can see which interesting topics are in this post.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 23 Posted 2006-11-15 07:24 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Finally back again!

Reply to post 18, the answer is: 29995.

The test code given:




@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



Explanation: This program was tested and passed under XP pro sp2.

To solve this problem, first we need to clarify that the number must end with 5, because only in this way, after conversion, it will be an even number and can be divided by 2; and the first digit must be 2......

[ Last edited by youxi01 on 2006-11-16 at 11:38 PM ]
Floor 24 Posted 2006-11-15 07:46 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Answer to post 20: The answer is 10 11 12 13 14



@echo off
echo Detecting 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 consecutive 5 natural numbers are: %num0% %num1% %num2% %num3% %num4%
pause>nul



Tested and passed under XP Pro SP2.

[ Last edited by youxi01 on 2006-11-16 at 11:38 PM ]
Floor 25 Posted 2006-11-15 08:10 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
At the request of namejm:


#Serial number! Solved? Unsolved

#01!
Find narcissistic numbers?

#02!
There are four numbers. When any three numbers are added together, the resulting sums are 84, 88, 99, 110 respectively. Find these four numbers?

#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 exactly consist of the ten digits from 0 to 9.
Ask, what number should this be?

#04!
A total of 4889 digits were used to number the pages of a dictionary. How many pages does this dictionary have? Answer: 1499

#05!
Acong 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?

#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 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?

#07!
The sum of five consecutive natural numbers can be divisible by 2, 3, 4, 5, 6 respectively. Find the smallest set of numbers that meets this condition.

#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 I was originally?

#09?
Farmer Jones said to his wife: "Hey, Maria, if I sell 75 chicks according to my way, then our chicken feed can last for 20 days. However, if I 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?

#10!
Among all five-digit numbers, how many have exactly two 3s?

#11!
Divide 17 into the sum of several natural numbers. What is the maximum product of these natural numbers?

#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?

#13!
The sum of the dividend, divisor and quotient is 181, and the quotient is 12. Find the dividend.


#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?

#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 of this number when divided by 15?

#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?



[ Last edited by zouzhxi on 2006-11-15 at 09:39 PM ]
Floor 26 Posted 2006-11-15 08:10 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Originally posted by youxi01 at 2006-11-14 18:24:
To solve this problem, first we need to clarify that the number must end with 5, because only in this way can it be an even number after conversion and be divisible by 2; and the first digit must be 2...

  The idea of 23F has flaws, because what we need to do is to simulate the problem statement with code. If we can directly deduce certain conditions, we can make full use of these conditions; if the conditions need to be deduced through more than two steps of reasoning, it is better not to use them and should be left to the code to handle; otherwise, since the conditions deduced through two steps of reasoning can be used, then what about three steps? Four steps? N steps? The last step is just included in the Nth step? In that case, we can completely write out the conclusion that needs to be deduced through N steps and thus completely abandon the code - although your result is correct in the end, it is suggested not to do this.

  Based on 23F, here is a code that solves the problem of 18F and tries to simulate the problem statement (very slow):

@echo off
setlocal enabledelayedexpansion
for /l %%i in (10001,2,99999) do (
set num=%%i
set num=!num:5=a!
if not "!num!"=="%%i" (
set num_tmp1=!num!
set num=!num:2=5!
if not "!num!"=="!num_tmp1!" (
set num=!num:a=2!
set /a num_tmp2=2*%%i+2
if !num! equ !num_tmp2! echo %%i
)
)
)
pause

  Then here is a faster code:

@echo off
setlocal enabledelayedexpansion
for /l %%i in (10005,5,99995) do (
set num=%%i
set num=!num:5=a!
if not "!num!"=="%%i" (
set num_tmp1=!num!
set num=!num:2=5!
if not "!num!"=="!num_tmp1!" (
set num=!num:a=2!
set /a num_tmp2=2*%%i+2
if !num! equ !num_tmp2! echo %%i
)
)
)
pause


  The code of 23F can be simplified as:

@echo off
setlocal enabledelayedexpansion
for /l %%i in (20005,5,29995) do (
set num=%%i
set num=!num:5=a!
set num=!num:2=5!
set num=!num:a=2!
set /a num_tmp=2*%%i+2
if !num! equ !num_tmp! echo %%i
)
pause


[ Last edited by namejm on 2006-11-15 at 12:57 PM" ]
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 27 Posted 2006-11-15 08:18 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
I can't agree with the statement of the "moderator" above: "Because what we need to do is to simulate the problem with code. If we can directly derive some conditions, we can make full use of these conditions; if conditions that need more than two steps of reasoning to be obtained".

I once wrote a problem of finding prime numbers within 100,000 with (pure) batch processing. According to the statement above, if we simulate the problem, the running efficiency of the written code is really not to be praised!

For some derivable conclusions, especially those that can be derived quickly, I think they can all be applied.
Floor 28 Posted 2006-11-15 08:31 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Hehe, the approach of not agreeing is correct because I didn't state my precondition: when we want to study certain algorithms, we should try to write code simulating the problem statement; if it's writing scripts, based on the principle of , we can make full use of all correctly derivable conditions - the reason for proposing the statement of trying to simulate here is because we are mainly discussing general algorithms here. Of course, it doesn't mean excluding highly technical code.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 29 Posted 2006-11-15 09:27 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

  When playing number games with batch processing, you need to pay attention to the range of numbers, otherwise overflow will occur.

  -2147483648——2147483647 (WINDOWS XP SP2 @ CMD Shell)
Floor 30 Posted 2006-11-15 12:14 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Not bad, there are many questions! Let's answer a few first!

### Question 8:
```
@echo off
rem After deduction, the first digit must be 1, (unless the unknown number is 1, and the case where it is 1 is also handled 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

```

### Question 9:
```
@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

```

### Question 10: Here is a relatively clever method: (the efficiency may be relatively high, not tested!)
```
@echo off
echo Detecting 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 Detection completed!
pause>nul
```

[ Last edited by youxi01 on 2006-11-16 at 11:41 PM ]
Forum Jump: