Wieferich primes: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 22: | Line 22: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{trans|BASIC256}} |
{{trans|BASIC256}} |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_IO; |
||
procedure Wieferich_Primes is |
procedure Wieferich_Primes is |
||
Line 62: | Line 62: | ||
end loop; |
end loop; |
||
end Wieferich_Primes;</ |
end Wieferich_Primes;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 72: | Line 72: | ||
=={{header|APL}}== |
=={{header|APL}}== |
||
'''Works in:''' [[Dyalog APL]] |
'''Works in:''' [[Dyalog APL]] |
||
< |
<syntaxhighlight lang="apl"> ⎕CY 'dfns' ⍝ import dfns namespace |
||
⍝ pco ← prime finder |
⍝ pco ← prime finder |
||
⍝ nats ← natural number arithmetic (uses strings) |
⍝ nats ← natural number arithmetic (uses strings) |
||
Line 79: | Line 79: | ||
wief 5000 |
wief 5000 |
||
1093 3511 |
1093 3511 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">wieferich?: function [n][ |
||
and? -> prime? n |
and? -> prime? n |
||
-> zero? (dec 2 ^ n-1) % n ^ 2 |
-> zero? (dec 2 ^ n-1) % n ^ 2 |
||
] |
] |
||
print ["Wieferich primes less than 5000:" select 1..5000 => wieferich?]</ |
print ["Wieferich primes less than 5000:" select 1..5000 => wieferich?]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 94: | Line 94: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
|||
<lang AWK> |
|||
# syntax: GAWK -f WIEFERICH_PRIMES.AWK |
# syntax: GAWK -f WIEFERICH_PRIMES.AWK |
||
# converted from FreeBASIC |
# converted from FreeBASIC |
||
Line 132: | Line 132: | ||
return(q == 1) |
return(q == 1) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 143: | Line 143: | ||
==={{header|BASIC256}}=== |
==={{header|BASIC256}}=== |
||
{{trans|FreeBASIC}} |
{{trans|FreeBASIC}} |
||
< |
<syntaxhighlight lang="freebasic">print "Wieferich primes less than 5000: " |
||
for i = 1 to 5000 |
for i = 1 to 5000 |
||
if isWeiferich(i) then print i |
if isWeiferich(i) then print i |
||
Line 169: | Line 169: | ||
end while |
end while |
||
return True |
return True |
||
end function</ |
end function</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Igual que la entrada de FreeBASIC.</pre> |
<pre>Igual que la entrada de FreeBASIC.</pre> |
||
Line 175: | Line 175: | ||
==={{header|PureBasic}}=== |
==={{header|PureBasic}}=== |
||
{{trans|FreeBASIC}} |
{{trans|FreeBASIC}} |
||
< |
<syntaxhighlight lang="purebasic">Procedure.i isPrime(n) |
||
Protected k |
Protected k |
||
Line 216: | Line 216: | ||
Next i |
Next i |
||
Input() |
Input() |
||
CloseConsole()</ |
CloseConsole()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Igual que la entrada de FreeBASIC.</pre> |
<pre>Igual que la entrada de FreeBASIC.</pre> |
||
==={{header|Run BASIC}}=== |
==={{header|Run BASIC}}=== |
||
< |
<syntaxhighlight lang="runbasic">print "Wieferich primes less than 5000: " |
||
for i = 1 to 5000 |
for i = 1 to 5000 |
||
if isWeiferich(i) then print i |
if isWeiferich(i) then print i |
||
Line 252: | Line 252: | ||
end if |
end if |
||
[exit] |
[exit] |
||
end function</ |
end function</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Igual que la entrada de FreeBASIC.</pre> |
<pre>Igual que la entrada de FreeBASIC.</pre> |
||
Line 258: | Line 258: | ||
==={{header|Yabasic}}=== |
==={{header|Yabasic}}=== |
||
{{trans|FreeBASIC}} |
{{trans|FreeBASIC}} |
||
< |
<syntaxhighlight lang="yabasic">print "Wieferich primes less than 5000: " |
||
for i = 2 to 5000 |
for i = 2 to 5000 |
||
if isWeiferich(i) print i |
if isWeiferich(i) print i |
||
Line 284: | Line 284: | ||
wend |
wend |
||
return True |
return True |
||
end sub</ |
end sub</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Igual que la entrada de FreeBASIC.</pre> |
<pre>Igual que la entrada de FreeBASIC.</pre> |
||
Line 291: | Line 291: | ||
=={{header|C}}== |
=={{header|C}}== |
||
{{trans|C++}} |
{{trans|C++}} |
||
< |
<syntaxhighlight lang="c">#include <stdbool.h> |
||
#include <stdio.h> |
#include <stdio.h> |
||
#include <stdint.h> |
#include <stdint.h> |
||
Line 360: | Line 360: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Wieferich primes less than 5000: |
<pre>Wieferich primes less than 5000: |
||
Line 367: | Line 367: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp">#include <cstdint> |
||
#include <iostream> |
#include <iostream> |
||
#include <vector> |
#include <vector> |
||
Line 419: | Line 419: | ||
for (uint64_t p : wieferich_primes(limit)) |
for (uint64_t p : wieferich_primes(limit)) |
||
std::cout << p << '\n'; |
std::cout << p << '\n'; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 430: | Line 430: | ||
=={{header|C#}}== |
=={{header|C#}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<syntaxhighlight lang="csharp">using System; |
||
using System.Collections.Generic; |
using System.Collections.Generic; |
||
using System.Linq; |
using System.Linq; |
||
Line 501: | Line 501: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Wieferich primes less that 5000: |
<pre>Wieferich primes less that 5000: |
||
Line 509: | Line 509: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Weiferich primes: Nigel Galloway. June 2nd., 2021 |
// Weiferich primes: Nigel Galloway. June 2nd., 2021 |
||
primes32()|>Seq.takeWhile((>)5000)|>Seq.filter(fun n->(2I**(n-1)-1I)%(bigint(n*n))=0I)|>Seq.iter(printfn "%d") |
primes32()|>Seq.takeWhile((>)5000)|>Seq.filter(fun n->(2I**(n-1)-1I)%(bigint(n*n))=0I)|>Seq.iter(printfn "%d") |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 522: | Line 522: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-02-05}} |
{{works with|Factor|0.99 2021-02-05}} |
||
< |
<syntaxhighlight lang="factor">USING: io kernel math math.functions math.primes prettyprint |
||
sequences ; |
sequences ; |
||
"Wieferich primes less than 5000:" print |
"Wieferich primes less than 5000:" print |
||
5000 primes-upto [ [ 1 - 2^ 1 - ] [ sq divisor? ] bi ] filter .</ |
5000 primes-upto [ [ 1 - 2^ 1 - ] [ sq divisor? ] bi ] filter .</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 534: | Line 534: | ||
=={{header|fermat}}== |
=={{header|fermat}}== |
||
< |
<syntaxhighlight lang="fermat"> |
||
Func Iswief(p)=Isprime(p)*Divides(p^2, 2^(p-1)-1). |
Func Iswief(p)=Isprime(p)*Divides(p^2, 2^(p-1)-1). |
||
for i=2 to 5000 do if Iswief(i) then !!i fi od |
for i=2 to 5000 do if Iswief(i) then !!i fi od |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}}<pre> |
{{out}}<pre> |
||
1093 |
1093 |
||
Line 545: | Line 545: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|Gforth}} |
{{works with|Gforth}} |
||
< |
<syntaxhighlight lang="forth">: prime? ( n -- ? ) here + c@ 0= ; |
||
: notprime! ( n -- ) here + 1 swap c! ; |
: notprime! ( n -- ) here + 1 swap c! ; |
||
Line 599: | Line 599: | ||
5000 wieferich_primes |
5000 wieferich_primes |
||
bye</ |
bye</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 609: | Line 609: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic"> |
||
#include "isprime.bas" |
#include "isprime.bas" |
||
Line 624: | Line 624: | ||
for i as uinteger = 1 to 5000 |
for i as uinteger = 1 to 5000 |
||
if iswief(i) then print i |
if iswief(i) then print i |
||
next i</ |
next i</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
{{libheader|Go-rcu}} |
{{libheader|Go-rcu}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 652: | Line 652: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 662: | Line 662: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">isPrime :: Integer -> Bool |
||
isPrime n |
isPrime n |
||
|n == 2 = True |
|n == 2 = True |
||
Line 680: | Line 680: | ||
main = do |
main = do |
||
putStrLn "Wieferich primes less than 5000:" |
putStrLn "Wieferich primes less than 5000:" |
||
print solution</ |
print solution</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Wieferich primes less than 5000: |
<pre>Wieferich primes less than 5000: |
||
Line 687: | Line 687: | ||
=={{header|J}}== |
=={{header|J}}== |
||
< |
<syntaxhighlight lang="j"> I.(1&p: * 0=*: | _1+2x^<:) i.5000 |
||
1093 3511</ |
1093 3511</syntaxhighlight> |
||
About 12 times faster: |
About 12 times faster: |
||
< |
<syntaxhighlight lang="j"> p: I. (0=*:|_1+2x^<:) I.1 p: i.5000 |
||
1093 3511</ |
1093 3511</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{trans|C++}} |
{{trans|C++}} |
||
< |
<syntaxhighlight lang="java">import java.util.*; |
||
public class WieferichPrimes { |
public class WieferichPrimes { |
||
Line 751: | Line 751: | ||
return result; |
return result; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 764: | Line 764: | ||
gojq supports unbounded-precision integer arithmetic and so is up to this task. |
gojq supports unbounded-precision integer arithmetic and so is up to this task. |
||
< |
<syntaxhighlight lang="jq">def is_prime: |
||
. as $n |
. as $n |
||
| if ($n < 2) then false |
| if ($n < 2) then false |
||
Line 789: | Line 789: | ||
# for the sake of infinite-precision integer arithmetic |
# for the sake of infinite-precision integer arithmetic |
||
def power($b): . as $a | reduce range(0; $b) as $i (1; .*$a); |
def power($b): . as $a | reduce range(0; $b) as $i (1; .*$a); |
||
</syntaxhighlight> |
|||
</lang> |
|||
'''The task''' |
'''The task''' |
||
< |
<syntaxhighlight lang="jq"># Input: the limit |
||
def wieferich: |
def wieferich: |
||
primes[] |
primes[] |
||
Line 798: | Line 798: | ||
5000 | wieferich |
5000 | wieferich |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 806: | Line 806: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">using Primes |
||
println(filter(p -> (big"2"^(p - 1) - 1) % p^2 == 0, primes(5000))) # [1093, 3511] |
println(filter(p -> (big"2"^(p - 1) - 1) % p^2 == 0, primes(5000))) # [1093, 3511] |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">ClearAll[WieferichPrimeQ] |
||
WieferichPrimeQ[n_Integer] := PrimeQ[n] && Divisible[2^(n - 1) - 1, n^2] |
WieferichPrimeQ[n_Integer] := PrimeQ[n] && Divisible[2^(n - 1) - 1, n^2] |
||
Select[Range[5000], WieferichPrimeQ]</ |
Select[Range[5000], WieferichPrimeQ]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{1093, 3511}</pre> |
<pre>{1093, 3511}</pre> |
||
Line 820: | Line 820: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{libheader|bignum}} |
{{libheader|bignum}} |
||
< |
<syntaxhighlight lang="nim">import math |
||
import bignum |
import bignum |
||
Line 839: | Line 839: | ||
if p.isPrime: |
if p.isPrime: |
||
if exp(two, p - 1, p * p) == 1: # Modular exponentiation. |
if exp(two, p - 1, p * p) == 1: # Modular exponentiation. |
||
echo p</ |
echo p</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 847: | Line 847: | ||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
< |
<syntaxhighlight lang="parigp">iswief(p)=if(isprime(p)&&(2^(p-1)-1)%p^2==0,1,0) |
||
for(N=1,5000,if(iswief(N),print(N)))</ |
for(N=1,5000,if(iswief(N),print(N)))</syntaxhighlight> |
||
{{out}}<pre>1093 |
{{out}}<pre>1093 |
||
3511</pre> |
3511</pre> |
||
Line 854: | Line 854: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
< |
<syntaxhighlight lang="perl">use feature 'say'; |
||
use ntheory qw(is_prime powmod); |
use ntheory qw(is_prime powmod); |
||
say 'Wieferich primes less than 5000: ' . join ', ', grep { is_prime($_) and powmod(2, $_-1, $_*$_) == 1 } 1..5000;</ |
say 'Wieferich primes less than 5000: ' . join ', ', grep { is_prime($_) and powmod(2, $_-1, $_*$_) == 1 } 1..5000;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Wieferich primes less than 5000: 1093, 3511</pre> |
<pre>Wieferich primes less than 5000: 1093, 3511</pre> |
||
Line 863: | Line 863: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<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 873: | Line 873: | ||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Weiferich primes less than 5000: %V\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">5000</span><span style="color: #0000FF;">),</span><span style="color: #000000;">weiferich</span><span style="color: #0000FF;">)})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Weiferich primes less than 5000: %V\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">5000</span><span style="color: #0000FF;">),</span><span style="color: #000000;">weiferich</span><span style="color: #0000FF;">)})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
Line 880: | Line 880: | ||
</pre> |
</pre> |
||
alternative (same results), should be significantly faster, in the (largely pointless!) hunt for larger numbers. |
alternative (same results), should be significantly faster, in the (largely pointless!) hunt for larger numbers. |
||
<!--< |
<!--<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 891: | Line 891: | ||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Weiferich primes less than 5000: %V\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">5000</span><span style="color: #0000FF;">),</span><span style="color: #000000;">weiferich</span><span style="color: #0000FF;">)})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Weiferich primes less than 5000: %V\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">5000</span><span style="color: #0000FF;">),</span><span style="color: #000000;">weiferich</span><span style="color: #0000FF;">)})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="picolisp">(de **Mod (X Y N) |
||
(let M 1 |
(let M 1 |
||
(loop |
(loop |
||
Line 907: | Line 907: | ||
(=1 (**Mod 2 (dec D) (* D D))) |
(=1 (**Mod 2 (dec D) (* D D))) |
||
(println D) ) |
(println D) ) |
||
(inc 'D (++ L)) ) )</ |
(inc 'D (++ L)) ) )</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 915: | Line 915: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">#!/usr/bin/python |
||
def isPrime(n): |
def isPrime(n): |
||
Line 941: | Line 941: | ||
for i in range(2, 5001): |
for i in range(2, 5001): |
||
if isWeiferich(i): |
if isWeiferich(i): |
||
print(i)</ |
print(i)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Wieferich primes less than 5000: |
<pre>Wieferich primes less than 5000: |
||
Line 951: | Line 951: | ||
<code>eratosthenes</code> and <code>isprime</code> are defined at [[Sieve of Eratosthenes#Quackery]]. |
<code>eratosthenes</code> and <code>isprime</code> are defined at [[Sieve of Eratosthenes#Quackery]]. |
||
< |
<syntaxhighlight lang="quackery"> 5000 eratosthenes |
||
[ dup isprime iff |
[ dup isprime iff |
||
Line 959: | Line 959: | ||
else [ drop false ] ] is wieferich ( n --> b ) |
else [ drop false ] ] is wieferich ( n --> b ) |
||
5000 times [ i^ wieferich if [ i^ echo cr ] ]</ |
5000 times [ i^ wieferich if [ i^ echo cr ] ]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 970: | Line 970: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket">#lang typed/racket |
||
(require math/number-theory) |
(require math/number-theory) |
||
Line 985: | Line 985: | ||
p)) |
p)) |
||
wieferich-primes<5000) |
wieferich-primes<5000) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 991: | Line 991: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang |
<syntaxhighlight lang="raku" line>put "Wieferich primes less than 5000: ", join ', ', ^5000 .grep: { .is-prime and not ( exp($_-1, 2) - 1 ) % .² };</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Wieferich primes less than 5000: 1093, 3511</pre> |
<pre>Wieferich primes less than 5000: 1093, 3511</pre> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
< |
<syntaxhighlight lang="rexx">/*REXX program finds and displays Wieferich primes which are under a specified limit N*/ |
||
parse arg n . /*obtain optional argument from the CL.*/ |
parse arg n . /*obtain optional argument from the CL.*/ |
||
if n=='' | n=="," then n= 5000 /*Not specified? Then use the default.*/ |
if n=='' | n=="," then n= 5000 /*Not specified? Then use the default.*/ |
||
Line 1,029: | Line 1,029: | ||
end /*k*/ /* [↑] only process numbers ≤ √ J */ |
end /*k*/ /* [↑] only process numbers ≤ √ J */ |
||
#= #+1; @.#= j; sq.#= j*j; !.j= 1 /*bump # Ps; assign next P; P sqare; P.*/ |
#= #+1; @.#= j; sq.#= j*j; !.j= 1 /*bump # Ps; assign next P; P sqare; P.*/ |
||
end /*j*/; return</ |
end /*j*/; return</syntaxhighlight> |
||
{{out|output|text= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |
||
Line 1,042: | Line 1,042: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">require "prime" |
||
puts Prime.each(5000).select{|p| 2.pow(p-1 ,p*p) == 1 } |
puts Prime.each(5000).select{|p| 2.pow(p-1 ,p*p) == 1 } |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>1093 |
<pre>1093 |
||
Line 1,052: | Line 1,052: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust">// [dependencies] |
||
// primal = "0.3" |
// primal = "0.3" |
||
// mod_exp = "1.0" |
// mod_exp = "1.0" |
||
Line 1,068: | Line 1,068: | ||
println!("{}", p); |
println!("{}", p); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,078: | Line 1,078: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">func is_wieferich_prime(p, base=2) { |
||
powmod(base, p-1, p**2) == 1 |
powmod(base, p-1, p**2) == 1 |
||
} |
} |
||
say ("Wieferich primes less than 5000: ", 5000.primes.grep(is_wieferich_prime))</ |
say ("Wieferich primes less than 5000: ", 5000.primes.grep(is_wieferich_prime))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,090: | Line 1,090: | ||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
{{trans|C++}} |
{{trans|C++}} |
||
< |
<syntaxhighlight lang="swift">func primeSieve(limit: Int) -> [Bool] { |
||
guard limit > 0 else { |
guard limit > 0 else { |
||
return [] |
return [] |
||
Line 1,155: | Line 1,155: | ||
for p in wieferichPrimes(limit: limit) { |
for p in wieferichPrimes(limit: limit) { |
||
print(p) |
print(p) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,167: | Line 1,167: | ||
{{libheader|Wren-math}} |
{{libheader|Wren-math}} |
||
{{libheader|Wren-big}} |
{{libheader|Wren-big}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/math" for Int |
||
import "/big" for BigInt |
import "/big" for BigInt |
||
Line 1,176: | Line 1,176: | ||
var den = p * p |
var den = p * p |
||
if (num % den == 0) System.print(p) |
if (num % den == 0) System.print(p) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |