Cipolla's algorithm: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 79: Line 79:
{{trans|Python}}
{{trans|Python}}


<lang 11l>F convertToBase(n, b)
<syntaxhighlight lang=11l>F convertToBase(n, b)
I (n < 2)
I (n < 2)
R [n]
R [n]
Line 125: Line 125:
print(‘Roots of 56 mod 101: ’cipolla(56, 101))
print(‘Roots of 56 mod 101: ’cipolla(56, 101))
print(‘Roots of 1 mod 11: ’cipolla(1, 11))
print(‘Roots of 1 mod 11: ’cipolla(1, 11))
print(‘Roots of 8219 mod 10007: ’cipolla(8219, 10007))</lang>
print(‘Roots of 8219 mod 10007: ’cipolla(8219, 10007))</syntaxhighlight>


{{out}}
{{out}}
Line 138: Line 138:
=={{header|C}}==
=={{header|C}}==
{{trans|FreeBasic}}
{{trans|FreeBasic}}
<lang c>#include <stdbool.h>
<syntaxhighlight lang=c>#include <stdbool.h>
#include <stdint.h>
#include <stdint.h>
#include <stdio.h>
#include <stdio.h>
Line 327: Line 327:


return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Find solution for n = 10 and p = 13
<pre>Find solution for n = 10 and p = 13
Line 348: Line 348:


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using System;
<syntaxhighlight lang=csharp>using System;
using System.Numerics;
using System.Numerics;


Line 424: Line 424:
}
}
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>(6, 7, True)
<pre>(6, 7, True)
Line 437: Line 437:
=={{header|D}}==
=={{header|D}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<lang D>import std.bigint;
<syntaxhighlight lang=D>import std.bigint;
import std.stdio;
import std.stdio;
import std.typecons;
import std.typecons;
Line 520: Line 520:
writeln(c("881398088036", "1000000000039"));
writeln(c("881398088036", "1000000000039"));
writeln(c("34035243914635549601583369544560650254325084643201", ""));
writeln(c("34035243914635549601583369544560650254325084643201", ""));
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Tuple!(BigInt, "x", BigInt, "y", bool, "b")(6, 7, true)
<pre>Tuple!(BigInt, "x", BigInt, "y", bool, "b")(6, 7, true)
Line 532: Line 532:


=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
<lang scheme>
<syntaxhighlight lang=scheme>
(lib 'struct)
(lib 'struct)
(lib 'types)
(lib 'types)
Line 584: Line 584:
(assert (mod= n (* x x) p)) ;; checking the result
(assert (mod= n (* x x) p)) ;; checking the result
(printf "Roots of %d are (%d,%d) (mod %d)" n x (% (- p x) p) p))
(printf "Roots of %d are (%d,%d) (mod %d)" n x (% (- p x) p) p))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 609: Line 609:
===The function===
===The function===
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_function Extensible Prime Generator (F#)]
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_function Extensible Prime Generator (F#)]
<lang fsharp>
<syntaxhighlight lang=fsharp>
// Cipolla's algorithm. Nigel Galloway: June 16th., 2019
// Cipolla's algorithm. Nigel Galloway: June 16th., 2019
let Cipolla n g =
let Cipolla n g =
Line 621: Line 621:
|_->let n,i=Seq.item α fE in ((Πn*n+Πi*i*b)%g)
|_->let n,i=Seq.item α fE in ((Πn*n+Πi*i*b)%g)
if fN 1I n ((g-1I)/2I) g<>1I then None else Some(fL 1I 0I 0 ((g+1I)/2I))
if fN 1I n ((g-1I)/2I) g<>1I then None else Some(fL 1I 0I 0 ((g+1I)/2I))
</syntaxhighlight>
</lang>
===The Task===
===The Task===
<lang fsharp>
<syntaxhighlight lang=fsharp>
let test=[(10I,13I);(56I,101I);(8218I,10007I);(8219I,10007I);(331575I,1000003I);(665165880I,1000000007I);(881398088036I,1000000000039I);(34035243914635549601583369544560650254325084643201I,10I**50+151I)]
let test=[(10I,13I);(56I,101I);(8218I,10007I);(8219I,10007I);(331575I,1000003I);(665165880I,1000000007I);(881398088036I,1000000000039I);(34035243914635549601583369544560650254325084643201I,10I**50+151I)]
test|>List.iter(fun(n,g)->match Cipolla n g with Some r->printfn "Cipolla %A %A -> %A (%A) check %A" n g r (g-r) ((r*r)%g) |_->printfn "Cipolla %A %A -> has no result" n g)
test|>List.iter(fun(n,g)->match Cipolla n g with Some r->printfn "Cipolla %A %A -> %A (%A) check %A" n g r (g-r) ((r*r)%g) |_->printfn "Cipolla %A %A -> has no result" n g)
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 643: Line 643:
{{trans|Sidef}}
{{trans|Sidef}}
{{works with|Factor|0.99 2020-08-14}}
{{works with|Factor|0.99 2020-08-14}}
<lang factor>USING: accessors assocs interpolate io kernel literals locals
<syntaxhighlight lang=factor>USING: accessors assocs interpolate io kernel literals locals
math math.extras math.functions ;
math math.extras math.functions ;


Line 693: Line 693:
[ 2dup - [I Roots of ${3} are (${1} ${0}) mod ${2}I] ]
[ 2dup - [I Roots of ${3} are (${1} ${0}) mod ${2}I] ]
[ [I No solution for (${}, ${})I] ] if* nl
[ [I No solution for (${}, ${})I] ] if* nl
] assoc-each</lang>
] assoc-each</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 710: Line 710:
Had a close look at the EchoLisp code for step 2.
Had a close look at the EchoLisp code for step 2.
Used the FreeBASIC code from the Miller-Rabin task for prime testing.
Used the FreeBASIC code from the Miller-Rabin task for prime testing.
<lang freebasic>' version 08-04-2017
<syntaxhighlight lang=freebasic>' version 08-04-2017
' compile with: fbc -s console
' compile with: fbc -s console
' maximum for p is 17 digits to be on the save side
' maximum for p is 17 digits to be on the save side
Line 896: Line 896:
Print : Print "hit any key to end program"
Print : Print "hit any key to end program"
Sleep
Sleep
End</lang>
End</syntaxhighlight>
{{out}}
{{out}}
<pre>Find solution for n = 10 and p = 13
<pre>Find solution for n = 10 and p = 13
Line 920: Line 920:
===GMP version===
===GMP version===
{{libheader|GMP}}
{{libheader|GMP}}
<lang freebasic>' version 12-04-2017
<syntaxhighlight lang=freebasic>' version 12-04-2017
' compile with: fbc -s console
' compile with: fbc -s console


Line 1,067: Line 1,067:
Print : Print "hit any key to end program"
Print : Print "hit any key to end program"
Sleep
Sleep
End</lang>
End</syntaxhighlight>
{{out}}
{{out}}
<pre>Find solution for n = 10 and p = 13
<pre>Find solution for n = 10 and p = 13
Line 1,096: Line 1,096:
===int===
===int===
Implementation following the pseudocode in the task description.
Implementation following the pseudocode in the task description.
<lang go>package main
<syntaxhighlight lang=go>package main


import "fmt"
import "fmt"
Line 1,158: Line 1,158:
fmt.Println(c(8219, 10007))
fmt.Println(c(8219, 10007))
fmt.Println(c(331575, 1000003))
fmt.Println(c(331575, 1000003))
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,169: Line 1,169:
===big.Int===
===big.Int===
Extra credit:
Extra credit:
<lang go>package main
<syntaxhighlight lang=go>package main


import (
import (
Line 1,228: Line 1,228:
fmt.Println(&R1)
fmt.Println(&R1)
fmt.Println(&R2)
fmt.Println(&R2)
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,241: Line 1,241:
Based on the echolisp implementation:
Based on the echolisp implementation:


<lang J>leg=: dyad define
<syntaxhighlight lang=J>leg=: dyad define
x (y&|)@^ (y-1)%2
x (y&|)@^ (y-1)%2
)
)
Line 1,274: Line 1,274:
assert. 'not a valid square root'
assert. 'not a valid square root'
end.
end.
)</lang>
)</syntaxhighlight>


Task examples:
Task examples:


<lang J> 10 cipolla 13
<syntaxhighlight lang=J> 10 cipolla 13
6 7
6 7
56 cipolla 101
56 cipolla 101
Line 1,294: Line 1,294:
208600591990 791399408049
208600591990 791399408049
34035243914635549601583369544560650254325084643201x cipolla (10^50x) + 151
34035243914635549601583369544560650254325084643201x cipolla (10^50x) + 151
17436881171909637738621006042549786426312886309400 82563118828090362261378993957450213573687113690751</lang>
17436881171909637738621006042549786426312886309400 82563118828090362261378993957450213573687113690751</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
{{works with|Java|8}}
{{works with|Java|8}}
<lang Java>import java.math.BigInteger;
<syntaxhighlight lang=Java>import java.math.BigInteger;
import java.util.function.BiFunction;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Function;
Line 1,406: Line 1,406:
System.out.println(c("34035243914635549601583369544560650254325084643201", ""));
System.out.println(c("34035243914635549601583369544560650254325084643201", ""));
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>(6, 7, true)
<pre>(6, 7, true)
Line 1,422: Line 1,422:


A Point is represented by a numeric array of length two (i.e. [x,y]).
A Point is represented by a numeric array of length two (i.e. [x,y]).
<lang jq># To take advantage of gojq's arbitrary-precision integer arithmetic:
<syntaxhighlight lang=jq># To take advantage of gojq's arbitrary-precision integer arithmetic:
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);


Line 1,499: Line 1,499:
;
;


exercise</lang>
exercise</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,515: Line 1,515:
=={{header|Julia}}==
=={{header|Julia}}==
{{trans|Perl}}
{{trans|Perl}}
<lang julia>using Primes
<syntaxhighlight lang=julia>using Primes


function legendre(n, p)
function legendre(n, p)
Line 1,561: Line 1,561:
println(r > 0 ? "Roots of $n are ($r, $(p - r)) mod $p." : "No solution for ($n, $p)")
println(r > 0 ? "Roots of $n are ($r, $(p - r)) mod $p." : "No solution for ($n, $p)")
end
end
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
Roots of 10 are (6, 7) mod 13.
Roots of 10 are (6, 7) mod 13.
Line 1,575: Line 1,575:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|Go}}
{{trans|Go}}
<lang scala>// version 1.2.0
<syntaxhighlight lang=scala>// version 1.2.0


import java.math.BigInteger
import java.math.BigInteger
Line 1,641: Line 1,641:
println(c("881398088036", "1000000000039"))
println(c("881398088036", "1000000000039"))
println(c("34035243914635549601583369544560650254325084643201", ""))
println(c("34035243914635549601583369544560650254325084643201", ""))
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,656: Line 1,656:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>ClearAll[Cipolla]
<syntaxhighlight lang=Mathematica>ClearAll[Cipolla]
Cipolla[n_, p_] := Module[{ls, omega2, nn, a, r, s},
Cipolla[n_, p_] := Module[{ls, omega2, nn, a, r, s},
ls = JacobiSymbol[n, p];
ls = JacobiSymbol[n, p];
Line 1,694: Line 1,694:
Cipolla[665165880, 1000000007]
Cipolla[665165880, 1000000007]
Cipolla[881398088036, 1000000000039]
Cipolla[881398088036, 1000000000039]
Cipolla[34035243914635549601583369544560650254325084643201, 10^50 + 151]</lang>
Cipolla[34035243914635549601583369544560650254325084643201, 10^50 + 151]</syntaxhighlight>
{{out}}
{{out}}
<pre>{6,7,True}
<pre>{6,7,True}
Line 1,708: Line 1,708:
{{trans|Kotlin}}
{{trans|Kotlin}}
{{libheader|bignum}}
{{libheader|bignum}}
<lang Nim>import options
<syntaxhighlight lang=Nim>import options
import bignum
import bignum


Line 1,787: Line 1,787:
let sols = c(n, p)
let sols = c(n, p)
if sols.isSome: echo sols.get()
if sols.isSome: echo sols.get()
else: echo "No solutions."</lang>
else: echo "No solutions."</syntaxhighlight>


{{out}}
{{out}}
Line 1,802: Line 1,802:
{{trans|Raku}}
{{trans|Raku}}
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>use bigint;
<syntaxhighlight lang=perl>use bigint;
use ntheory qw(is_prime);
use ntheory qw(is_prime);


Line 1,852: Line 1,852:
$r ? printf "Roots of %d are (%d, %d) mod %d\n", $n, $r, $p-$r, $p
$r ? printf "Roots of %d are (%d, %d) mod %d\n", $n, $r, $p-$r, $p
: print "No solution for ($n, $p)\n"
: print "No solution for ($n, $p)\n"
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Roots of 10 are (6, 7) mod 13
<pre>Roots of 10 are (6, 7) mod 13
Line 1,865: Line 1,865:
{{trans|Kotlin}}
{{trans|Kotlin}}
{{libheader|Phix/mpfr}}
{{libheader|Phix/mpfr}}
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 1,960: Line 1,960:
<span style="color: #0000FF;">?{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cipolla</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">)}</span>
<span style="color: #0000FF;">?{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cipolla</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">)}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
Obviously were you to use that in anger, you would probably rip out a few mpz_get_str() and return NULL/false rather than "0"/"false", etc.
Obviously were you to use that in anger, you would probably rip out a few mpz_get_str() and return NULL/false rather than "0"/"false", etc.
{{out}}
{{out}}
Line 1,977: Line 1,977:
=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
{{trans|Go}}
{{trans|Go}}
<lang PicoLisp># from @lib/rsa.l
<syntaxhighlight lang=PicoLisp># from @lib/rsa.l
(de **Mod (X Y N)
(de **Mod (X Y N)
(let M 1
(let M 1
Line 2,037: Line 2,037:
(println (ci 665165880 1000000007))
(println (ci 665165880 1000000007))
(println (ci 881398088036 1000000000039))
(println (ci 881398088036 1000000000039))
(println (ci 34035243914635549601583369544560650254325084643201 (+ (** 10 50) 151)))</lang>
(println (ci 34035243914635549601583369544560650254325084643201 (+ (** 10 50) 151)))</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,051: Line 2,051:


=={{header|Python}}==
=={{header|Python}}==
<lang python>
<syntaxhighlight lang=python>
#Converts n to base b as a list of integers between 0 and b-1
#Converts n to base b as a list of integers between 0 and b-1
#Most-significant digit on the left
#Most-significant digit on the left
Line 2,102: Line 2,102:
print "Roots of 1 mod 11: " +str(cipolla(1,11))
print "Roots of 1 mod 11: " +str(cipolla(1,11))
print "Roots of 8219 mod 10007: " +str(cipolla(8219,10007))
print "Roots of 8219 mod 10007: " +str(cipolla(8219,10007))
</syntaxhighlight>
</lang>
{{out}}
{{out}}


Line 2,115: Line 2,115:
{{trans|EchoLisp}}
{{trans|EchoLisp}}


<lang racket>#lang racket
<syntaxhighlight lang=racket>#lang racket


(require math/number-theory)
(require math/number-theory)
Line 2,188: Line 2,188:
(report-Cipolla 881398088036 1000000000039)
(report-Cipolla 881398088036 1000000000039)
(report-Cipolla 34035243914635549601583369544560650254325084643201
(report-Cipolla 34035243914635549601583369544560650254325084643201
100000000000000000000000000000000000000000000000151))</lang>
100000000000000000000000000000000000000000000000151))</syntaxhighlight>


{{out}}
{{out}}
Line 2,206: Line 2,206:
{{trans|Sidef}}
{{trans|Sidef}}


<lang perl6># Legendre operator (𝑛│𝑝)
<syntaxhighlight lang=raku line># Legendre operator (𝑛│𝑝)
sub infix:<│> (Int \𝑛, Int \𝑝 where 𝑝.is-prime && (𝑝 != 2)) {
sub infix:<│> (Int \𝑛, Int \𝑝 where 𝑝.is-prime && (𝑝 != 2)) {
given 𝑛.expmod( (𝑝-1) div 2, 𝑝 ) {
given 𝑛.expmod( (𝑝-1) div 2, 𝑝 ) {
Line 2,265: Line 2,265:
!! "No solution for ($n, $p)"
!! "No solution for ($n, $p)"
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>Roots of 10 are (6, 7) mod 13
<pre>Roots of 10 are (6, 7) mod 13
Line 2,280: Line 2,280:
=={{header|Sage}}==
=={{header|Sage}}==
{{works with|Sage|7.6}}
{{works with|Sage|7.6}}
<lang sage>
<syntaxhighlight lang=sage>
def eulerCriterion(a, p):
def eulerCriterion(a, p):
return -1 if pow(a, int((p-1)/2), p) == p-1 else 1
return -1 if pow(a, int((p-1)/2), p) == p-1 else 1
Line 2,334: Line 2,334:


return sorted(out)
return sorted(out)
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,352: Line 2,352:
=={{header|Scala}}==
=={{header|Scala}}==
===Imperative solution===
===Imperative solution===
<lang Scala>object CipollasAlgorithm extends App {
<syntaxhighlight lang=Scala>object CipollasAlgorithm extends App {
private val BIG = BigInt(10).pow(50) + BigInt(151)
private val BIG = BigInt(10).pow(50) + BigInt(151)


Line 2,405: Line 2,405:
}
}


}</lang>
}</syntaxhighlight>
{{Out}}See it running in your browser by [https://scalafiddle.io/sf/QQBsMza/3 ScalaFiddle (JavaScript, non JVM)] or by [https://scastie.scala-lang.org/NEP5hOWmSBqqpwmF30LpUA Scastie (JVM)].
{{Out}}See it running in your browser by [https://scalafiddle.io/sf/QQBsMza/3 ScalaFiddle (JavaScript, non JVM)] or by [https://scastie.scala-lang.org/NEP5hOWmSBqqpwmF30LpUA Scastie (JVM)].


=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Go}}
{{trans|Go}}
<lang ruby>func cipolla(n, p) {
<syntaxhighlight lang=ruby>func cipolla(n, p) {


legendre(n, p) == 1 || return nil
legendre(n, p) == 1 || return nil
Line 2,458: Line 2,458:
say "No solution for (#{n}, #{p})"
say "No solution for (#{n}, #{p})"
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Roots of 10 are (6 7) mod 13
<pre>Roots of 10 are (6 7) mod 13
Line 2,471: Line 2,471:
=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
{{trans|C#}}
{{trans|C#}}
<lang vbnet>Imports System.Numerics
<syntaxhighlight lang=vbnet>Imports System.Numerics


Module Module1
Module Module1
Line 2,542: Line 2,542:
End Sub
End Sub


End Module</lang>
End Module</syntaxhighlight>
{{out}}
{{out}}
<pre>(6, 7, True)
<pre>(6, 7, True)
Line 2,557: Line 2,557:
{{libheader|Wren-big}}
{{libheader|Wren-big}}
{{libheader|Wren-dynamic}}
{{libheader|Wren-dynamic}}
<lang ecmascript>import "/big" for BigInt
<syntaxhighlight lang=ecmascript>import "/big" for BigInt
import "/dynamic" for Tuple
import "/dynamic" for Tuple


Line 2,615: Line 2,615:
System.print(c.call("665165880", "1000000007"))
System.print(c.call("665165880", "1000000007"))
System.print(c.call("881398088036", "1000000000039"))
System.print(c.call("881398088036", "1000000000039"))
System.print(c.call("34035243914635549601583369544560650254325084643201", ""))</lang>
System.print(c.call("34035243914635549601583369544560650254325084643201", ""))</syntaxhighlight>


{{out}}
{{out}}
Line 2,632: Line 2,632:
{{trans|EchoLisp}}
{{trans|EchoLisp}}
Uses lib GMP (GNU MP Bignum Library).
Uses lib GMP (GNU MP Bignum Library).
<lang zkl>var [const] BN=Import("zklBigNum"); //libGMP
<syntaxhighlight lang=zkl>var [const] BN=Import("zklBigNum"); //libGMP
fcn modEq(a,b,p) { (a-b)%p==0 }
fcn modEq(a,b,p) { (a-b)%p==0 }
fcn Legendre(a,p){ a.powm((p - 1)/2,p) }
fcn Legendre(a,p){ a.powm((p - 1)/2,p) }
Line 2,662: Line 2,662:
println("Roots of %d are (%d,%d) (mod %d)".fmt(n,x,(p-x)%p,p));
println("Roots of %d are (%d,%d) (mod %d)".fmt(n,x,(p-x)%p,p));
return(x,(p-x)%p);
return(x,(p-x)%p);
}</lang>
}</syntaxhighlight>
<lang zkl>foreach n,p in (T(
<syntaxhighlight lang=zkl>foreach n,p in (T(
T(10,13),T(56,101),T(8218,10007),T(8219,10007),T(331575,1000003),
T(10,13),T(56,101),T(8218,10007),T(8219,10007),T(331575,1000003),
T(665165880,1000000007),T(881398088036,1000000000039),
T(665165880,1000000007),T(881398088036,1000000000039),
Line 2,669: Line 2,669:
BN(10).pow(50) + 151) )){
BN(10).pow(50) + 151) )){
try{ Cipolla(n,p) }catch{ println(__exception) }
try{ Cipolla(n,p) }catch{ println(__exception) }
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>