Super-Poulet numbers: Difference between revisions

Content added Content deleted
(Added Wren)
(→‎{{header|Wren}}: Tweak, bit quicker.)
Line 125: Line 125:
import "./gmp" for Mpz
import "./gmp" for Mpz
import "./fmt" for Fmt
import "./fmt" for Fmt

var one = Mpz.one


var isSuperPoulet = Fn.new { |x|
var isSuperPoulet = Fn.new { |x|
if (Int.isPrime(x)) return false
if (Int.isPrime(x)) return false
var bx = Mpz.from(x)
var bx = Mpz.from(x)
if (Mpz.two.modPow(bx-1, bx) != 1) return false
if (Mpz.two.modPow(x-1, bx) != one) return false
var t = Mpz.new()
var t = Mpz.new()
return Int.divisors(x).skip(1).all { |d| t.uiPow(2, d).sub(2).isDivisibleUi(d) }
return Int.divisors(x).skip(1).all { |d| t.uiPow(2, d).sub(2).isDivisibleUi(d) }