Wieferich primes: Difference between revisions

Content added Content deleted
m (Thundergnat moved page Weiferich primes to Wieferich primes: Misspelled name)
m (Fix typo throughout, I misspelled it in the first place)
Line 87: Line 87:
sequences ;
sequences ;


"Weiferich primes less than 5000:" print
"Wieferich primes less than 5000:" print
5000 primes-upto [ [ 1 - 2^ 1 - ] [ sq divisor? ] bi ] filter .</lang>
5000 primes-upto [ [ 1 - 2^ 1 - ] [ sq divisor? ] bi ] filter .</lang>
{{out}}
{{out}}
<pre>
<pre>
Weiferich primes less than 5000:
Wieferich primes less than 5000:
V{ 1093 3511 }
V{ 1093 3511 }
</pre>
</pre>
Line 172: Line 172:
use ntheory 'is_prime';
use ntheory 'is_prime';


say 'Weiferich primes less than 5000: ' . join ', ', grep { is_prime($_) and not ( (2**($_-1) -1) % $_**2 ) } 1..5000;</lang>
say 'Wieferich primes less than 5000: ' . join ', ', grep { is_prime($_) and not ( (2**($_-1) -1) % $_**2 ) } 1..5000;</lang>
{{out}}
{{out}}
<pre>Weiferich primes less than 5000: 1093, 3511</pre>
<pre>Wieferich primes less than 5000: 1093, 3511</pre>


=={{header|Phix}}==
=={{header|Phix}}==
Line 180: Line 180:
<span style="color: #008080;">include</span> <span style="color: #7060A8;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #7060A8;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #7060A8;">mpz</span> <span style="color: #000000;">z</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpz_init</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">mpz</span> <span style="color: #000000;">z</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpz_init</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">weiferich</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">wieferich</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">mpz_set_str</span><span style="color: #0000FF;">(</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'1'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">),</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">mpz_set_str</span><span style="color: #0000FF;">(</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'1'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">),</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">mpz_fdiv_q_ui</span><span style="color: #0000FF;">(</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">*</span><span style="color: #000000;">p</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">mpz_fdiv_q_ui</span><span style="color: #0000FF;">(</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">*</span><span style="color: #000000;">p</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span>
<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;">"Wieferich 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;">wieferich</span><span style="color: #0000FF;">)})</span>
<!--</lang>-->
<!--</lang>-->
{{out}}
{{out}}
<pre>
<pre>
Weiferich primes less than 5000: {1093,3511}
Wieferich primes less than 5000: {1093,3511}
</pre>
</pre>


Line 197: Line 197:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program finds and displays Weiferich primes which are under a specified limit N*/
<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 203: Line 203:
numeric digits max(9, length(2**n) ) /*calculate # of decimal digits needed.*/
numeric digits max(9, length(2**n) ) /*calculate # of decimal digits needed.*/
call genP /*build array of semaphores for primes.*/
call genP /*build array of semaphores for primes.*/
title= ' Weiferich primes that are < ' commas(n) /*title for the output. */
title= ' Wieferich primes that are < ' commas(n) /*title for the output. */
w= length(title) + 2 /*width of field for the primes listed.*/
w= length(title) + 2 /*width of field for the primes listed.*/
say ' index │'center(title, w) /*display the title for the output. */
say ' index │'center(title, w) /*display the title for the output. */
say '───────┼'center("" , w, '─') /* " a sep for the output. */
say '───────┼'center("" , w, '─') /* " a sep for the output. */
wp= 0 /*initialize number of Weiferich primes*/
wp= 0 /*initialize number of Wieferich primes*/
do j=1 to #; p= @.j; pm= p - 1 /*search for Weiferich primes in range.*/
do j=1 to #; p= @.j; pm= p - 1 /*search for Wieferich primes in range.*/
if (2**pm - 1) // p**2\==0 then iterate /*P**2 not evenly divide 2**(P-1) - 1?*/
if (2**pm - 1) // p**2\==0 then iterate /*P**2 not evenly divide 2**(P-1) - 1?*/
wp= wp + 1 /*bump the counter of Weiferich primes.*/
wp= wp + 1 /*bump the counter of Wieferich primes.*/
say center(wp, 7)'│' center(commas(p), w) /*display the Weiferich prime to term. */
say center(wp, 7)'│' center(commas(p), w) /*display the Wieferich prime to term. */
end /*j*/
end /*j*/


Line 238: Line 238:
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>
index │ Weiferich primes that are < 5,000
index │ Wieferich primes that are < 5,000
───────┼──────────────────────────────────────
───────┼──────────────────────────────────────
1 │ 1,093
1 │ 1,093
Line 244: Line 244:
───────┴──────────────────────────────────────
───────┴──────────────────────────────────────


Found 2 Weiferich primes that are < 5,000
Found 2 Wieferich primes that are < 5,000
</pre>
</pre>


Line 254: Line 254:


var primes = Int.primeSieve(5000)
var primes = Int.primeSieve(5000)
System.print("Weiferich primes < 5000:")
System.print("Wieferich primes < 5000:")
for (p in primes) {
for (p in primes) {
var num = (BigInt.one << (p - 1)) - 1
var num = (BigInt.one << (p - 1)) - 1
Line 263: Line 263:
{{out}}
{{out}}
<pre>
<pre>
Weiferich primes < 5000:
Wieferich primes < 5000:
1093
1093
3511
3511