Wieferich primes: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|J}}) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 22:
=={{header|Ada}}==
{{trans|BASIC256}}
<
procedure Wieferich_Primes is
Line 62:
end loop;
end Wieferich_Primes;</
{{out}}
<pre>
Line 72:
=={{header|APL}}==
'''Works in:''' [[Dyalog APL]]
<
⍝ pco ← prime finder
⍝ nats ← natural number arithmetic (uses strings)
Line 79:
wief 5000
1093 3511
</syntaxhighlight>
=={{header|Arturo}}==
<
and? -> prime? n
-> zero? (dec 2 ^ n-1) % n ^ 2
]
print ["Wieferich primes less than 5000:" select 1..5000 => wieferich?]</
{{out}}
Line 94:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f WIEFERICH_PRIMES.AWK
# converted from FreeBASIC
Line 132:
return(q == 1)
}
</syntaxhighlight>
{{out}}
<pre>
Line 143:
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<
for i = 1 to 5000
if isWeiferich(i) then print i
Line 169:
end while
return True
end function</
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
Line 175:
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<
Protected k
Line 216:
Next i
Input()
CloseConsole()</
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
==={{header|Run BASIC}}===
<
for i = 1 to 5000
if isWeiferich(i) then print i
Line 252:
end if
[exit]
end function</
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
Line 258:
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<
for i = 2 to 5000
if isWeiferich(i) print i
Line 284:
wend
return True
end sub</
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
Line 291:
=={{header|C}}==
{{trans|C++}}
<
#include <stdio.h>
#include <stdint.h>
Line 360:
return 0;
}</
{{out}}
<pre>Wieferich primes less than 5000:
Line 367:
=={{header|C++}}==
<
#include <iostream>
#include <vector>
Line 419:
for (uint64_t p : wieferich_primes(limit))
std::cout << p << '\n';
}</
{{out}}
Line 430:
=={{header|C#}}==
{{trans|Java}}
<
using System.Collections.Generic;
using System.Linq;
Line 501:
}
}
}</
{{out}}
<pre>Wieferich primes less that 5000:
Line 509:
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<
// 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")
</syntaxhighlight>
{{out}}
<pre>
Line 522:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<
sequences ;
"Wieferich primes less than 5000:" print
5000 primes-upto [ [ 1 - 2^ 1 - ] [ sq divisor? ] bi ] filter .</
{{out}}
<pre>
Line 534:
=={{header|fermat}}==
<
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
</syntaxhighlight>
{{out}}<pre>
1093
Line 545:
=={{header|Forth}}==
{{works with|Gforth}}
<
: notprime! ( n -- ) here + 1 swap c! ;
Line 599:
5000 wieferich_primes
bye</
{{out}}
Line 609:
=={{header|FreeBASIC}}==
<
#include "isprime.bas"
Line 624:
for i as uinteger = 1 to 5000
if iswief(i) then print i
next i</
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<
import (
Line 652:
}
}
}</
{{out}}
Line 662:
=={{header|Haskell}}==
<
isPrime n
|n == 2 = True
Line 680:
main = do
putStrLn "Wieferich primes less than 5000:"
print solution</
{{out}}
<pre>Wieferich primes less than 5000:
Line 687:
=={{header|J}}==
<
1093 3511</
About 12 times faster:
<
1093 3511</
=={{header|Java}}==
{{trans|C++}}
<
public class WieferichPrimes {
Line 751:
return result;
}
}</
{{out}}
Line 764:
gojq supports unbounded-precision integer arithmetic and so is up to this task.
<
. as $n
| if ($n < 2) then false
Line 789:
# for the sake of infinite-precision integer arithmetic
def power($b): . as $a | reduce range(0; $b) as $i (1; .*$a);
</syntaxhighlight>
'''The task'''
<
def wieferich:
primes[]
Line 798:
5000 | wieferich
</syntaxhighlight>
{{out}}
<pre>
Line 806:
=={{header|Julia}}==
<
println(filter(p -> (big"2"^(p - 1) - 1) % p^2 == 0, primes(5000))) # [1093, 3511]
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
WieferichPrimeQ[n_Integer] := PrimeQ[n] && Divisible[2^(n - 1) - 1, n^2]
Select[Range[5000], WieferichPrimeQ]</
{{out}}
<pre>{1093, 3511}</pre>
Line 820:
=={{header|Nim}}==
{{libheader|bignum}}
<
import bignum
Line 839:
if p.isPrime:
if exp(two, p - 1, p * p) == 1: # Modular exponentiation.
echo p</
{{out}}
Line 847:
=={{header|PARI/GP}}==
<
for(N=1,5000,if(iswief(N),print(N)))</
{{out}}<pre>1093
3511</pre>
Line 854:
=={{header|Perl}}==
{{libheader|ntheory}}
<
use ntheory qw(is_prime powmod);
say 'Wieferich primes less than 5000: ' . join ', ', grep { is_prime($_) and powmod(2, $_-1, $_*$_) == 1 } 1..5000;</
{{out}}
<pre>Wieferich primes less than 5000: 1093, 3511</pre>
Line 863:
=={{header|Phix}}==
<!--<
<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>
Line 873:
<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>
<!--</
{{out}}
Line 880:
</pre>
alternative (same results), should be significantly faster, in the (largely pointless!) hunt for larger numbers.
<!--<
<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>
Line 891:
<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>
<!--</
=={{header|PicoLisp}}==
<
(let M 1
(loop
Line 907:
(=1 (**Mod 2 (dec D) (* D D)))
(println D) )
(inc 'D (++ L)) ) )</
{{out}}
<pre>
Line 915:
=={{header|Python}}==
<
def isPrime(n):
Line 941:
for i in range(2, 5001):
if isWeiferich(i):
print(i)</
{{out}}
<pre>Wieferich primes less than 5000:
Line 951:
<code>eratosthenes</code> and <code>isprime</code> are defined at [[Sieve of Eratosthenes#Quackery]].
<
[ dup isprime iff
Line 959:
else [ drop false ] ] is wieferich ( n --> b )
5000 times [ i^ wieferich if [ i^ echo cr ] ]</
{{out}}
Line 970:
=={{header|Racket}}==
<
(require math/number-theory)
Line 985:
p))
wieferich-primes<5000)
</syntaxhighlight>
{{out}}
Line 991:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
{{out}}
<pre>Wieferich primes less than 5000: 1093, 3511</pre>
=={{header|REXX}}==
<
parse arg n . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n= 5000 /*Not specified? Then use the default.*/
Line 1,029:
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; sq.#= j*j; !.j= 1 /*bump # Ps; assign next P; P sqare; P.*/
end /*j*/; return</
{{out|output|text= when using the default input:}}
<pre>
Line 1,042:
=={{header|Ruby}}==
<
puts Prime.each(5000).select{|p| 2.pow(p-1 ,p*p) == 1 }
</syntaxhighlight>
{{out}}
<pre>1093
Line 1,052:
=={{header|Rust}}==
<
// primal = "0.3"
// mod_exp = "1.0"
Line 1,068:
println!("{}", p);
}
}</
{{out}}
Line 1,078:
=={{header|Sidef}}==
<
powmod(base, p-1, p**2) == 1
}
say ("Wieferich primes less than 5000: ", 5000.primes.grep(is_wieferich_prime))</
{{out}}
<pre>
Line 1,090:
=={{header|Swift}}==
{{trans|C++}}
<
guard limit > 0 else {
return []
Line 1,155:
for p in wieferichPrimes(limit: limit) {
print(p)
}</
{{out}}
Line 1,167:
{{libheader|Wren-math}}
{{libheader|Wren-big}}
<
import "/big" for BigInt
Line 1,176:
var den = p * p
if (num % den == 0) System.print(p)
}</
{{out}}
|