1.5.2 The Algorithm of Cornacchia

15
1.5.2 The Algorithm of Cornacchia

description

1.5.2 The Algorithm of Cornacchia. 今回の内容. Algorithm1.5.2(Cornacchia) Algorithm1.5.2 の実装 Algorithm1.5.2 の Example Algorithm1.5.3(Modified-Cornacchia). Algorithm1.5.2(Cornacchia). より、一般的に・・・・. Algorithm1.5.2(Cornacchia). Input: Output: Step1: Step2:. Algorithm1.5.2(Cornacchia). Step3: - PowerPoint PPT Presentation

Transcript of 1.5.2 The Algorithm of Cornacchia

1.5.2The Algorithm of Cornacchia

今回の内容 Algorithm1.5.2(Cornacchia)

Algorithm1.5.2の実装 Algorithm1.5.2の Example

Algorithm1.5.3(Modified-Cornacchia)

Algorithm1.5.2(Cornacchia)

が存在するをみたす

を与えたとき

Zyx

pyx

pnumberprimep

,

,))4(mod1(:22

?

?,

,prime odd:,22

0

は何か存在するとしたらそれは存在するかをみたす

を与えたとき

Zyxpdyx

pZd

より、一般的に・・・・

Algorithm1.5.2(Cornacchia) Input: Output: Step1:

Step2:

.,1

).4.12Algorithm1 (

整数解を持たないなら

を用いる

k

p

dk

)0,numberPrime:,(, pdpZdpd

),(, 22 が存在すればの整数解 yxpdyxZyx

とする,,

)とする,ば(

するをみたすように2/,

)を用い.5.11(Algorithm

.を求める,をみたす)(mod

0

0

00

02

0

plxbpa

xpx

pxpx

xpdx

必要ならは

Algorithm1.5.2(Cornacchia)

Step3:

Step4:

を繰り返すの間 rbbabarlb ,),(mod,

),(),(,

,

1.7.3)(Algorithm/)(

,,2

2

cbyx

dbpc

bpd

そうでないとき

整数解は存在しないではないならばが平方数

またはで割り切れないが

この bが xの候補になるEuclid Algorithmの適

Algorithm1.5.2(Cornacchia) 証明について

F. Morain, J.-L. Nicolas による証明がある .

(URL)

http://web.math.hr/~duje/tbkript/tbksem.html

          について Primes of the form x2+ny2 (Cox, David A. 著 ) に多くのことが書かれている .

pdyx 22

Pythonでの実装import mathimport kro1import shanksimport square_test

def cornacchia(d,p): k = kro1.kro_b(-d,p) if k == -1: return "no solution" x0= shanks.shanks(-d,p) if x0 == 0: return "no solution" if x0 < p/2: x0 = p – x0

a = p b = x0 l = int(math.floor(math.sqrt(p))) while b > l: r = a % b a = b b = r c = (p - (b ** 2)) / d t = squaretest.square_test(c) if ((d % (p - (b ** 2)) != 0) or square_test.square_test(c) > 1): return (b,t) return "no solution"

Algorithm1.5.1

Algorithm1.7.3

平方剰余の計算

Pythonでの実装 (Algorithm1.5.1)import mathimport randomimport kro1

def shanks(c,g): temp = g -1 e = 0 while temp % 2 == 0: temp = temp // 2 e = e + 1

q = (g-1) // 2**e k = 0 while k != -1: n =int(math.floor(1000*random.random()))

k = kro1.kro_b(n,g) z = (n ** q) % g y = z r = e x = (c ** ((q - 1) // 2)) % g b = (c * (x ** 2)) % g x = (c * x) % g while b % g != 1: m = 1 while ((b ** (2 ** m)) % g) != 1: m = m + 1 if m == r: print “[a] is not a quadratic residue mod p" return 0 t = (y ** (2 ** (r - m - 1))) % g y = (t ** 2) % g r = m % g x = (x * t) % g b = (b * y) % g return x

Pythonでの実装 (Algorithm1.7.1&3)import math

def square_test(c): q11 = [] q63 = [] q64 = [] q65 = []

for k in range(0,11): q11.append(0) for k in range(0,6): q11[(k ** 2) % 11] =1

for k in range(0,63): q63.append(0) for k in range(0,32): q63[(k ** 2) % 63] = 1

for k in range(0,64): q64.append(0) for k in range(0,32): q64[(k ** 2) % 64] = 1

for k in range(0,65): q65.append(0) for k in range(0,33): q65[(k ** 2) % 65] = 1

t = c % 64 if q64[t] == 0: return "sono1" r = c % 45045 if q63[r % 63] == 0: return "sono2" if q65[r % 65] == 0: return "sono3" if q11[r % 11] == 0: return "sono4"

x = c y = 0 y = math.floor ((x + math.floor(c/x))/2) while y < x: x = y y = math.floor ((x + math.floor(c/x))/2) if int(math.floor(x ** 2)) == int(math.floor(c)): return 1 else: return 0

Example

Step1:

Step2:

Step3: a b r97

80 -80

17 517

12 512 5

5

Step4:

1.4.12)(algorithm197

2

972 22 yx

1.5.1)(algorithm170 xと置き換える8017970 x

997,80,97 lba

)6,5(),(

)6362/72(/)(

)2()722597(22

2

yx

dbp

dbp

Euclid Algorithmを適用

p/2<x0<pとなるように

平方数になっている

Algorithm1.5.3(Modified Cornacchia)

を求めるをみたす x,y

pDpDyx prime) odd:1,or0(422

D|4 x|2)4/,2/'(

' 22

Ddxx

pdyx

① )8(mod1D

)12(

)8(mod422

とおくkp

yx

even:,, yx①かつ),2/',2/'(

'' 22

Ddyyxx

pyx

(1)

(2)

(3) )8(mod5D の偶奇は決定できないyx,

Algorithm1.5.3(Modified Cornacchia)

(3)の場合 ,Algorithm1.5.2を適用することができない

1.5.2を修正した Algorithm1.5.3を用いることで ,この問題を解決することができる

)8(mod5Dのとき

Algorithm1.5.3(Modified Cornacchia)

Input:

Output: Step1:

Step2:

pDtsZD

p

4Dand)4(mod1or0..

numberprime:

0

),4(, 22 が存在すればの解 yxpyDxZyx

解は存在しないそれ以外のとき

らばが整数の平方であるなのとき

,

)1,8(),(

,8

,2

Dyx

D

p

解を持たないなら

を用いる

,1

.).4.12Algorithm1 (

k

p

Dk

1.5.2との違い

Algorithm1.5.3(Modified Cornacchia) Step3:

Step4:

とする2,,2

とする,02mod

)を用い.5.11(Algorithm

を求める,をみたす)(mod

0

0

0

02

0

plxbpa

xpx

x

xpDx

と合同でないときでがる

を繰り返すの間 rbbabarlb ,),(mod,

1.5.2との違い

Algorithm1.5.3(Modified Cornacchia)

Step5:

),(),(,

,

)3.7.1Algorithm(/)(

,,42

2

cbyx

Dbpc

bpD

そうでないとき

解は存在しないでないならば

が平方数

またはで割り切れないが