🎓

64bit数の素数判定

に公開
7

Discussion

Mizar/みざーMizar/みざー

Forisek, Michal and Jakub Jancina. “Fast Primality Testing for Integers That Fit into a Machine Word.” Conference on Current Trends in Theory and Practice of Informatics (2015).
https://ceur-ws.org/Vol-1326/020-Forisek.pdf

N の値をハッシュ関数によって処理し、Miller-Rabin素数テストで範囲内の全ての合成数を漏れなく判定できる底の値をハッシュ表に登録しておくことで、 Miller-Rabin素数テストの実行回数・実行時間を削減できるとするpaper.

  • FJ32_256: N\lt 2^{32} の時、 256要素のハッシュ表を用いて 底の値 \lbrace b \rbrace を表引きし、 \lbrace b \rbrace を底とする 1回のMiller-Rabin素数テストで素数判定するバリアント。 (paper内にソースコード有り)
  • FJ64_16k: N\lt 2^{64} の時、 16384要素のハッシュ表を用いて 底の値 (ハッシュ表の各要素は2個の底の値 \lbrace b_1, b_2 \rbrace をpackしている) を表引きし、 \lbrace 2, b_1, b_2 \rbrace を底とする 3回の Miller-Rabin素数テストで素数判定するバリアント。 実行例: https://judge.yosupo.jp/submission/140049
  • FJ64_262k: N\lt 2^{64} の時、 262144要素のハッシュ表を用いて 底の値 \lbrace b \rbrace を表引きし、 \lbrace 2, b \rbrace を底とする 2回の Miller-Rabin素数テストで素数判定するバリアント。 実行例: https://judge.yosupo.jp/submission/139998
  • ソースコード: https://people.ksp.sk/~misof/primes/
Agate PrisAgate Pris

すみません、こちらの記事の sqrt_newton を自作のライブラリに含めて公開したい (ライセンスは未定) のですが大丈夫ですか?

著作表記などできるだけご意向に沿いたいと考えています。「むしろ表記しないでほしいし、勝手にしてほしい」という感じであればそのようにしたいと思います。

以上です、よろしくお願い致します。

Agate PrisAgate Pris

大変素早い返信ありがとうございます。

CC0 との旨、承知いたしました。

Mizar/みざーMizar/みざー

https://www.techneon.com/download/is.prime.64.base.data

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:
: An odd number in the range 2^32 to 2^64 is prime if it passes an SPRP-2 test
: and one or two more SPRP tests using bases in this table.
:
: The table has 16384 16 bit entries designating a pair of bases.  Select an
: element using a hash of the odd number with:  (#AD625B89 _* N) // 18
:
: The operator "_*" is unsigned 32 bit multiplication and "//" shifts right.
: This hashing mechanism originated with Steven Worley's 32 bit primality test.
:
: 2^32 to 2^49:  Pass SPRP-2 and a second SPRP test using the hashed base.
:
: 2^49 to 2^64:  Pass an addition SPRP test using one of 8 bases selected
:                using the upper 3 bits of the hashed base.  These bases are:
:                   0 .. 7 ==> {15, 135, 13, 60, 15, 117, 65, 29}
:
:     N = 871_87753_77449
:     SPRP( N, 2 ) = 1
:     Hash = #d4ee_f6f1 // 18 = #353b = 13627
:     Base = 687
:     SPRP( N, 687 ) = 1                       (prime)
:
:     N = 865_17769_13431                      (555871 * 15564361)
:     SPRP( N, 2 ) = 1
:     Hash = #3d6c_a94f // 18 = #5fb = 3931
:     Base = 767
:     SPRP( N, 767 ) = 0                       (composite)
:
:     N = 3315_29345_21928_21991
:     SPRP( N, 2 ) = 1
:     Hash = #40eda9f // 18 = #103 = 259
:     Base = 8638
:     SPRP( N, 8638 ) = 1
:     Base = Second[ Base // 13 ] = 135
:     SPRP( N, 135 ) = 1                       (prime)
:
:     N = 1152_96599_65919_97761               (619937093 * 1859811277)
:     SPRP( N, 2 ) = 1
:     Hash = #9417_38c9 // 18 = #2505 = 9477
:     Base = 1941
:     SPRP( N, 1941 ) = 1
:     Base = Second[ Base // 13 ] = 15
:     SPRP( N, 15 ) = 0                        (composite)
:
:* Copyright 2018 Bradley Berg   < (My last name) @ t e c h n e o n . c o m >
:*
:* Permission to use, copy, modify, and distribute this software for any
:* purpose with or without fee is hereby granted, provided that the above
:* copyright notice and this permission notice appear in all copies.
:*
:
: This algorithm is deliberately unpatented. The license above also
: lets you even freely use it in commercial code.
:
: Primality testing using a hash table of bases originated with Steven Worley.
:...............................................................................