Cipolla's algorithm: Difference between revisions
m
→{{header|Wren}}: Minor tidy
Thundergnat (talk | contribs) m (Automated syntax highlighting fixup (second round - minor fixes)) |
m (→{{header|Wren}}: Minor tidy) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 2,076:
return (x1[0],-x1[0]%p)
print
print
print
print
print
</syntaxhighlight>
{{out}}▼
▲{{out}}
<pre>Roots of 2 mod 7: (4, 3)▼
<pre>
Roots of 8218 mod 10007: (9872, 135)
Roots of 56 mod 101: (37, 64)
Line 2,090 ⟶ 2,091:
Roots of 8219 mod 10007: ()
</pre>
=={{header|Racket}}==
{{trans|EchoLisp}}
Line 2,442 ⟶ 2,444:
Roots of 881398088036 are (791399408049 208600591990) mod 1000000000039
Roots of 34035243914635549601583369544560650254325084643201 are (82563118828090362261378993957450213573687113690751 17436881171909637738621006042549786426312886309400) mod 100000000000000000000000000000000000000000000000151</pre>
Simpler implementation:
<syntaxhighlight lang="ruby">func cipolla(n, p) {
kronecker(n, p) == 1 || return nil
var (a, ω) = (
0..Inf -> lazy.map {|a|
[a, submod(a*a, n, p)]
}.first_by {|t|
kronecker(t[1], p) == -1
}...
)
var r = lift(Mod(Quadratic(a, 1, ω), p)**((p+1)>>1))
r.b == 0 ? r.a : nil
}</syntaxhighlight>
=={{header|Visual Basic .NET}}==
{{trans|C#}}
Line 2,529 ⟶ 2,551:
{{libheader|Wren-big}}
{{libheader|Wren-dynamic}}
<syntaxhighlight lang="
import "./dynamic" for Tuple
var Point = Tuple.create("Point", ["x", "y"])
Line 2,600 ⟶ 2,622:
[82563118828090362261378993957450213573687113690751, 17436881171909637738621006042549786426312886309400, true]
</pre>
=={{header|zkl}}==
{{trans|EchoLisp}}
|