Super-Poulet numbers: Difference between revisions

Add Mathematica/Wolfram Language implementation
m (→‎{{header|Wren}}: Changed to Wren S/H)
(Add Mathematica/Wolfram Language implementation)
 
Line 289:
The first super-Poulet number over 10 million is the 317th one, which is 10031653
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
{{trans|Python}}
<syntaxhighlight lang="Mathematica">
(*Define the super-Poulet number test*)
IsSuperPoulet[n_Integer] :=
Module[{divisors, condition1, condition2}, divisors = Divisors[n];
condition1 = Not[PrimeQ[n]] && Mod[2^(n - 1), n] == 1;
condition2 = AllTrue[Most@divisors, Mod[2^# - 2, #] == 0 &];
condition1 && condition2];
 
(*Generate super-Poulet numbers up to 1,100,000*)
superPoulets = Select[Range[2, 1100000], IsSuperPoulet];
 
(*Print the first 20 super-Poulet numbers*)
Print["The first 20 super-Poulet numbers are: ",
superPoulets[[1 ;; 20]]];
 
(*Find and print the first super-Poulet number over 1 million*)
firstOverOneMillion = First@Select[superPoulets, # > 1000000 &];
idx1m = Position[superPoulets, firstOverOneMillion][[1, 1]];
Print["The first super-Poulet number over 1 million is the ", idx1m,
"th one, which is ", firstOverOneMillion];
</syntaxhighlight>
{{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 first super-Poulet number over 1 million is the 109th one, which is 1016801
</pre>
 
 
=={{header|Nim}}==
337

edits