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:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Discussion][Exploration] Using batch processing to make interesting math problems DigestI View 36,412 Replies 139
Floor 31 Posted 2006-11-15 14:47 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
=============================
The 11th question is a bit more difficult. Using high school mathematics knowledge, it can be proved that for any number greater than or equal to 4, it can be expressed as the sum of two numbers, and the product of these two numbers is greater than or equal to the number. According to this inference, all numbers will eventually be broken down into such forms: A*A*A*A.... where A is 2 or 3 (because only 2 and 3 cannot be broken down further, and the remaining part must be only 2 and 3). So we can get the following code: (The answer is 486, I don't know if it's correct ^-^)

@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


==================================
The 12th question seems relatively simple, but actually it's a bit difficult..

@echo off
echo Detecting 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 smallest natural number is:!num!
echo.
echo Detection 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))


=============================================
13th question



@echo off
echo Detecting 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 There are such numbers, dividend: %%a divisor: %%b quotient:!num!
)
)
)
echo.
echo Detection completed!
pause>nul


[ Last edited by youxi01 on 2006-11-16 at 11:33 PM ]
Floor 32 Posted 2006-11-15 21:42 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
The title has been updated...
Floor 33 Posted 2006-11-16 02:44 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
First ask the building owner: 1. Isn't the twelfth question solved? 2. Is the answer to the eleventh question correct?

For question fourteen, mental arithmetic may be faster because there is only 20, which is 2 more than a multiple of 3, so the answer is it (can be proved)!

The program code is:

@echo off
set /a num=15+16+18+19+20+31
set Tnum=15 16 18 19 20 31
setlocal enabledelayedexpansion
rem ==========================
rem Question fourteen:
for %%i in (15 16 18 19 20 31) do call :test %%i
echo The remaining package mass is:!result1!
echo The two packages 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))


[ Last edited by youxi01 on 2006-11-16 at 11:34 PM ]
Floor 34 Posted 2006-11-16 03:11 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Brother zouzhxi, please add the building number of the problem solver and the link below the title of the index content in the index post on the first floor. So that when forum visitors see the first post on the first floor, they can quickly understand the title index within a few seconds. And quickly click the link to enter the corresponding index page (because the building number prompt allows quick finding). This is very convenient and effective for the future indexing, searching, reference, communication, and reprinting of important and excellent resources in the forum ~ : )


  #01!
  Find narcissistic numbers?

  ************************** It is suggested to add the building numbers and URL links of different problem solvers here  **************************
  If there are multiple problem solvers, add multiple URL links to different pages and building numbers : )




Use batch processing solutions to solve and simulate content related to mathematical algorithms and data structures. It inherently contains a certain amount of batch processing applications and operation skills.

However, since the application of its data structure and algorithm is completed by batch processing operation simulation, and it also contains some skills and usage experience of batch processing applications, it is suggested to appropriately add Chinese annotations for reference and learning by netizens who hope to further improve in mathematics and batch processing ~ : )

Moreover, this is also a relatively "rare" knowledge post about mathematical content in batch processing ~ : )
So it is suggested to strive for excellence, to lay a higher foundation for increasing the highlights of the forum and the spread of influential posts in the forum ~ : )

[ Last edited by redtek on 2006-11-16 at 03:19 AM ]
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 35 Posted 2006-11-16 05:36 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Reply to the owner: The code running result for question 12 is indeed: 25, and the question has been solved! I want to ask if the answer to question 11 is 486?!

==============
Question 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


[ Last edited by youxi01 on 2006-11-16 at 11:34 PM ]
Floor 36 Posted 2006-11-16 05:41 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
Reply to the upstairs:
Yes,
Decomposed into: 3×3×3×3×3×2=486
This product is the largest.

The code result of your 12F:


[ Last edited by zouzhxi on 2006-11-16 at 05:51 AM ]
Floor 37 Posted 2006-11-16 05:54 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
1、For the first sub-question of question 16, if I think about it, it's too wasteful to write code:
It's very easy to prove that P must be even and must also be a prime number, so it can only be 2
2、As for the second sub-question, I think the answer should be 4. It can be solved by using the relevant knowledge of high school sequences and permutations and combinations. If I just write code for this problem, it's really.... I'm working hard to write a relatively general-purpose code
Floor 38 Posted 2006-11-16 06:01 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Re 36F, sorry, the answer to question 12 was pasted incorrectly, it was pasted into the test code! Please see the updated code!
Floor 39 Posted 2006-11-16 06:44 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
The question has been updated...
Floor 40 Posted 2006-11-16 23:14 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
===========================================
Here, no code is written at 16.1 because there's nothing much to write ^_^, the answer should be 5012
Paste the code for 16.2 below:



@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

::Handle 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
))


[ Last edited by youxi01 on 2006-11-16 at 11:35 PM ]
Floor 41 Posted 2006-11-16 23:18 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
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 youxi01 enclose the code part with [code] and [/code], which is convenient to distinguish the code part from the non-code part and also facilitates others' copy-paste.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 42 Posted 2006-11-16 23:28 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
===========================================
Question 17: Mathematical Olympiad problem. It is easy to know that the answer is 2^64 - 1. The important issue is how to calculate the extremely large number 2^64. Direct calculation is definitely not feasible, so we have to take the "detour" method. I call the method I adopted the "clock - type segmented calculation method". If it is not original, please forgive my rashness!

The following code divides the data into 6 segments, each segment 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, and add the carried data to the previous segment of data, and so on. This code currently supports multiplying 2 continuously for 200 times. Of course, you can "modify" it to calculate more massive numbers.

1. The following is the code for calculating 2^n:


@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 carry data and the calculation formula of 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 previous 1 is borrowed from the previous data segment; adding a 1 in front is to prevent the occurrence of situations like set /a test=0003!

set /a num%%a=1!tmp:~-6!
rem ========================================================================

rem The previous segment of data adds the carry number of the subsequent segment of data and subtracts 1, because a 1 is "borrowed"!
set /a num!Inum!+=!tmp:~0,-6!-1
)
)
)
rem ===================================================================
rem Tail - cleaning work. Because for debugging, the method of "borrowing" data is adopted above, and now it is restored!

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 ===================================================================
echo %num1% %num2% %num3% %num4% %num5% %num6%

pause>nul



2. To completely meet the requirements of the problem, please copy the following code!


@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 carry data and the calculation formula of 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 previous 1 is borrowed from the previous data segment; adding a 1 in front is to prevent the occurrence of situations like set /a test=0003!

set /a num%%a=1!tmp:~-6!
rem ========================================================================

rem The previous segment of data adds the carry number of the subsequent segment of data and subtracts 1, because a 1 is "borrowed"!
set /a num!Inum!+=!tmp:~0,-6!-1
)
)
)
set /a num6-=1
rem ===================================================================
rem Tail - cleaning work. Because for debugging, the method of "borrowing" data is adopted above, and now it is restored!

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


[ Last edited by youxi01 on 2006-11-17 at 12:33 AM ]
Floor 43 Posted 2006-11-16 23:31 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
========================================
Question 18: This is purely a problem of permutations and combinations. Actually, it's about using batch processing to handle the permutations and combinations formula!
Code: The result obtained is 1023. I don't know if it's correct?



@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 There are !Result! types of currency values
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


[ Last edited by youxi01 on 2006-11-16 at 11:37 PM ]
Floor 44 Posted 2006-11-16 23:55 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
Re 42F:
By the way,
It's just that there are two more 0s in front of the number and spaces in the middle of the number. It doesn't look like an answer, but a group of arrays... Can it be removed...

Re 43F:
At first, I miscalculated. Later, I found out that I need to subtract 1 at the end.
My initial answer was: for 1024
I didn't exclude the situation where none of the combinations are selected...
The answer is: 1023
Floor 45 Posted 2006-11-17 00:34 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
The post with ID 42F has been modified as you wished!
Forum Jump: