-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprime.rb
37 lines (31 loc) · 1.06 KB
/
prime.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def sqrt(a)
begv = 1
endv = a
while endv > begv + 1
mid = (endv + begv)/2
if mid ** 2 <= a
begv = mid
else
endv = mid
end
end
return begv
end
N1 = 179769313486231590772930519078902473361797697894230657273430081157732675805505620686985379449212982959585501387537164015710139858647833778606925583497541085196591615128057575940752635007475935288710823649949940771895617054361149474865046711015101563940680527540071584560878577663743040086340742855278549092581
a1 = sqrt(N1)+1
x1 = sqrt(a1*a1 - N1)
p1 = a1 - x1
q1 = a1 + x1
puts "p_1 = #{p1}"
puts "q_1 = #{q1}"
N2 = 648455842808071669662824265346772278726343720706976263060439070378797308618081116462714015276061417569195587321840254520655424906719892428844841839353281972988531310511738648965962582821502504990264452100885281673303711142296421027840289307657458645233683357077834689715838646088239640236866252211790085787877
(sqrt(N2)..N2).each do |a2|
x2 = sqrt(a2*a2 - N2)
p2 = a2 - x2
q2 = a2 + x2
if (p2*q2-N2) == 0 then
puts "p_2 = #{p2}"
puts "q_2 = #{q2}"
break
end
end