素數簡單探索

聲明:歡迎批評指正

寫作原因:今天看書,看到梅森素數,說到:大素數用於現代密碼設計領域,其原理是:將一個很大的數分解成若干素數的乘積非常困難,但將幾個素數相乘卻容易得多。因此想用批處理寫一個處理100000以內(10,100,1000,10000,100000)兩個素數相乘得到的最大數的程序,因此得此文

說明:

1.素數的獲取用已知的1000以內的素數表獲得,參考網址:https://baike.baidu.com/item/1000%E8%B4%A8%E6%95%B0%E8%A1%A8/18345635?fr=aladdin

2.前提:10以內顯示1位數*1位數的最大數,100以內顯示1位數*2位數的最大數,1000以內顯示2位數*2位數的最大數,10000以內顯示2位數*3位數的最大數,100000以內顯示3位數*3位數的最大數。

3.只是簡單探索的文章,不要期望太大:)

4.批處理用記事本保存爲"生成素數.bat",保存時選擇文件類型爲所有文件,然後在文件名對話框中輸入生成素數.bat,把one.txt,two.txt,three.txt文件與批處理文件放到一個目錄中,one.txt是1位數的素數,two.txt是兩位數的素數,three.txt是三位數的素數,可以修改代碼得到其他位數相乘的最大數


Let's Go!

生成素數.bat代碼:

@echo off
setlocal enabledelayedexpansion
echo $顯示2位數(10),3位數(100),4位數(1000),5位數(10000),6位數(100000)以內幾個素數相乘的最大值程序(10以內1位*1位,100以內1位*2位,1000以內2位*2位,10000以內2位*3位,100000以內3位*3位)$
echo.
set /a maxnum=0
set /a num1=0
set /a num2=0
set /p digits=請輸入多少以內(10,100,1000,10000,100000): 
if !digits! equ 10 (
for /f %%i in (one.txt) do (
for /f %%j in (one.txt) do (
set /a tmp=%%i*%%j
if !maxnum! equ 0 (
set /a maxnum=!tmp!
set /a num1=%%i
set /a num2=%%j
)
if !tmp! gtr !maxnum! (
if !tmp! leq 10 (
set /a maxnum=!tmp!
set /a num1=%%i
set /a num2=%%j
)
)
)
)
)
if !digits! equ 100 (
for /f %%i in (one.txt) do (
for /f %%j in (two.txt) do (
set /a tmp=%%i*%%j
if !maxnum! equ 0 (
set /a maxnum=!tmp!
set /a num1=%%i
set /a num2=%%j
)
if !tmp! gtr !maxnum! (
if !tmp! leq 100 (
set /a maxnum=!tmp!
set /a num1=%%i
set /a num2=%%j
)
)
)
)
)
if !digits! equ 1000 (
for /f %%i in (two.txt) do (
for /f %%j in (two.txt) do (
set /a tmp=%%i*%%j
if !maxnum! equ 0 (
set /a maxnum=!tmp!
set /a num1=%%i
set /a num2=%%j
)
if !tmp! gtr !maxnum! (
if !tmp! leq 1000 (
set /a maxnum=!tmp!
set /a num1=%%i
set /a num2=%%j
)
)
)
)
)
if !digits! equ 10000 (
for /f %%i in (two.txt) do (
for /f %%j in (three.txt) do (
set /a tmp=%%i*%%j
if !maxnum! equ 0 (
set /a maxnum=!tmp!
set /a num1=%%i
set /a num2=%%j
)
if !tmp! gtr !maxnum! (
if !tmp! leq 10000 (
set /a maxnum=!tmp!
set /a num1=%%i
set /a num2=%%j
)
)
)
)
)
if !digits! equ 100000 (
for /f %%i in (three.txt) do (
for /f %%j in (three.txt) do (
set /a tmp=%%i*%%j
if !maxnum! equ 0 (
set /a maxnum=!tmp!
set /a num1=%%i
set /a num2=%%j
)
if !tmp! gtr !maxnum! (
if !tmp! leq 100000 (
set /a maxnum=!tmp!
set /a num1=%%i
set /a num2=%%j
)
)
)
)
)
echo !num1!*!num2!=!maxnum!
pause

exit


one.txt代碼:

2
3
5

7


two.txt代碼:

11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89

97


three.txt代碼:

101
103
107
109
113
127
131
137
139
149
151
157
163
167
173
179
181
191
193
197
199
211
223
227
229
233
239
241
251
257
263
269
271
277
281
283
293
307
311
313
317
331
337
347
349
353
359
367
373
379
383
389
397
401
409
419
421
431
433
439
443
449
457
461
463
467
479
487
491
499
503
509
521
523
541
547
557
563
569
571
577
587
593
599
601
607
613
617
619
631
641
643
647
653
659
661
673
677
683
691
701
709
719
727
733
739
743
751
757
761
769
773
787
797
809
811
821
823
827
829
839
853
857
859
863
877
881
883
887
907
911
919
929
937
941
947
953
967
971
977
983
991
997

(全文完)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章