Super-Poulet numbers: Difference between revisions
Content added Content deleted
m (typo) |
(Added Wren) |
||
Line 116: | Line 116: | ||
Index and value of first super-Poulet greater than ten million: |
Index and value of first super-Poulet greater than ten million: |
||
317th super-Poulet number == 10,031,653 |
317th super-Poulet number == 10,031,653 |
||
</pre> |
|||
=={{header|Wren}}== |
|||
{{libheader|Wren-math}} |
|||
{{libheader|Wren-gmp}} |
|||
{{libheader|Wren-fmt}} |
|||
<lang ecmascript>import "./math" for Int |
|||
import "./gmp" for Mpz |
|||
import "./fmt" for Fmt |
|||
var isSuperPoulet = Fn.new { |x| |
|||
if (Int.isPrime(x)) return false |
|||
var bx = Mpz.from(x) |
|||
if (Mpz.two.modPow(bx-1, bx) != 1) return false |
|||
var t = Mpz.new() |
|||
return Int.divisors(x).skip(1).all { |d| t.uiPow(2, d).sub(2).isDivisibleUi(d) } |
|||
} |
|||
var count = 0 |
|||
var first20 = List.filled(20, 0) |
|||
var x = 3 |
|||
while (count < 20) { |
|||
if (isSuperPoulet.call(x)) { |
|||
first20[count] = x |
|||
count = count + 1 |
|||
} |
|||
x = x + 2 // Poulet numbers are always odd |
|||
} |
|||
System.print("The first 20 super-Poulet numbers are:") |
|||
System.print(first20) |
|||
System.print() |
|||
var limit = 1e6 |
|||
while (true) { |
|||
if (isSuperPoulet.call(x)) { |
|||
count = count + 1 |
|||
if (x > limit) { |
|||
Fmt.print("The $r super-Poulet number and the first over $,d is $,d.", count, limit, x) |
|||
if (limit == 1e6) limit = 1e7 else return |
|||
} |
|||
} |
|||
x = x + 2 |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
The first 20 super-Poulet numbers are: |
|||
[341, 1387, 2047, 2701, 3277, 4033, 4369, 4681, 5461, 7957, 8321, 10261, 13747, 14491, 15709, 18721, 19951, 23377, 31417, 31609] |
|||
The 109th super-Poulet number and the first over 1,000,000 is 1,016,801. |
|||
The 317th super-Poulet number and the first over 10,000,000 is 10,031,653. |
|||
</pre> |
</pre> |