Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/Repunit-primes/00-META.yaml
Normal file
2
Task/Repunit-primes/00-META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Repunit_primes
|
||||
48
Task/Repunit-primes/00-TASK.txt
Normal file
48
Task/Repunit-primes/00-TASK.txt
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
[[wp:Repunit|Repunit]] is a [[wp:Portmanteau|portmanteau]] of the words "repetition" and "unit", with unit being "unit value"... or in laymans terms, '''1'''. So 1, 11, 111, 1111 & 11111 are all repunits.
|
||||
|
||||
Every standard integer base has repunits since every base has the digit 1. This task involves finding the repunits in different bases that are prime.
|
||||
|
||||
In base two, the repunits 11, 111, 11111, 1111111, etc. are prime. (These correspond to the [[wp:Mersenne_prime|Mersenne primes]].)
|
||||
|
||||
In base three: 111, 1111111, 1111111111111, etc.
|
||||
|
||||
''Repunit primes, by definition, are also [[circular primes]].''
|
||||
|
||||
Any repunit in any base having a composite number of digits is necessarily composite. Only repunits (in any base) having a prime number of digits ''might'' be prime.
|
||||
|
||||
|
||||
Rather than expanding the repunit out as a giant list of '''1'''s or converting to base 10, it is common to just list the ''number'' of '''1'''s in the repunit; effectively the digit count. The base two repunit primes listed above would be represented as: 2, 3, 5, 7, etc.
|
||||
|
||||
Many of these sequences exist on [[oeis:|OEIS]], though they aren't specifically listed as "repunit prime digits" sequences.
|
||||
|
||||
Some bases have very few repunit primes. Bases 4, 8, and likely 16 have only one. Base 9 has none at all. Bases above 16 may have repunit primes as well... but this task is getting large enough already.
|
||||
|
||||
|
||||
;Task
|
||||
|
||||
* For bases 2 through 16, Find and show, here on this page, the repunit primes as digit counts, up to a limit of 1000.
|
||||
|
||||
|
||||
;Stretch
|
||||
|
||||
* Increase the limit to 2700 (or as high as you have patience for.)
|
||||
|
||||
|
||||
;See also
|
||||
|
||||
;* [[wp:Repunit#Repunit_primes|Wikipedia: Repunit primes]]
|
||||
;* [[oeis:A000043|OEIS:A000043 - Mersenne exponents: primes p such that 2^p - 1 is prime. Then 2^p - 1 is called a Mersenne prime]] (base 2)
|
||||
;* [[oeis:A028491|OEIS:A028491 - Numbers k such that (3^k - 1)/2 is prime]] (base 3)
|
||||
;* [[oeis:A004061|OEIS:A004061 - Numbers n such that (5^n - 1)/4 is prime]] (base 5)
|
||||
;* [[oeis:A004062|OEIS:A004062 - Numbers n such that (6^n - 1)/5 is prime]] (base 6)
|
||||
;* [[oeis:A004063|OEIS:A004063 - Numbers k such that (7^k - 1)/6 is prime]] (base 7)
|
||||
;* [[oeis:A004023|OEIS:A004023 - Indices of prime repunits: numbers n such that 11...111 (with n 1's) = (10^n - 1)/9 is prime]] (base 10)
|
||||
;* [[oeis:A005808|OEIS:A005808 - Numbers k such that (11^k - 1)/10 is prime]] (base 11)
|
||||
;* [[oeis:A004064|OEIS:A004064 - Numbers n such that (12^n - 1)/11 is prime]] (base 12)
|
||||
;* [[oeis:A016054|OEIS:A016054 - Numbers n such that (13^n - 1)/12 is prime]] (base 13)
|
||||
;* [[oeis:A006032|OEIS:A006032 - Numbers k such that (14^k - 1)/13 is prime]] (base 14)
|
||||
;* [[oeis:A006033|OEIS:A006033 - Numbers n such that (15^n - 1)/14 is prime]] (base 15)
|
||||
;* [[Circular primes|Related task: Circular primes]]
|
||||
|
||||
|
||||
|
||||
22
Task/Repunit-primes/ALGOL-68/repunit-primes.alg
Normal file
22
Task/Repunit-primes/ALGOL-68/repunit-primes.alg
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
BEGIN # find repunit (all digits are 1 ) primes in various bases #
|
||||
INT max base = 16;
|
||||
INT max repunit digits = 1000;
|
||||
PR precision 3000 PR # set precision of LONG LONG INT #
|
||||
# 16^1000 has ~1200 digits but the primality test needs more #
|
||||
PR read "primes.incl.a68" PR # include prime utilities #
|
||||
[]BOOL prime = PRIMESIEVE max repunit digits;
|
||||
FOR base FROM 2 TO max base DO
|
||||
LONG LONG INT repunit := 1;
|
||||
print( ( whole( base, -2 ), ":" ) );
|
||||
FOR digits TO max repunit digits DO
|
||||
IF prime[ digits ] THEN
|
||||
IF is probably prime( repunit ) THEN
|
||||
# found a prime repunit in the current base #
|
||||
print( ( " ", whole( digits, 0 ) ) )
|
||||
FI
|
||||
FI;
|
||||
repunit *:= base +:= 1
|
||||
OD;
|
||||
print( ( newline ) )
|
||||
OD
|
||||
END
|
||||
15
Task/Repunit-primes/Arturo/repunit-primes.arturo
Normal file
15
Task/Repunit-primes/Arturo/repunit-primes.arturo
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
getRepunit: function [n,b][
|
||||
result: 1
|
||||
loop 1..dec n 'z ->
|
||||
result: result + b^z
|
||||
return result
|
||||
]
|
||||
|
||||
loop 2..16 'base [
|
||||
print [
|
||||
pad (to :string base) ++ ":" 4
|
||||
join.with:", " to [:string] select 2..1001 'x ->
|
||||
and? -> prime? x
|
||||
-> prime? getRepunit x base
|
||||
]
|
||||
]
|
||||
35
Task/Repunit-primes/C++/repunit-primes.cpp
Normal file
35
Task/Repunit-primes/C++/repunit-primes.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <future>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <gmpxx.h>
|
||||
#include <primesieve.hpp>
|
||||
|
||||
std::vector<uint64_t> repunit_primes(uint32_t base,
|
||||
const std::vector<uint64_t>& primes) {
|
||||
std::vector<uint64_t> result;
|
||||
for (uint64_t prime : primes) {
|
||||
mpz_class repunit(std::string(prime, '1'), base);
|
||||
if (mpz_probab_prime_p(repunit.get_mpz_t(), 25) != 0)
|
||||
result.push_back(prime);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::vector<uint64_t> primes;
|
||||
const uint64_t limit = 2700;
|
||||
primesieve::generate_primes(limit, &primes);
|
||||
std::vector<std::future<std::vector<uint64_t>>> futures;
|
||||
for (uint32_t base = 2; base <= 36; ++base) {
|
||||
futures.push_back(std::async(repunit_primes, base, primes));
|
||||
}
|
||||
std::cout << "Repunit prime digits (up to " << limit << ") in:\n";
|
||||
for (uint32_t base = 2, i = 0; base <= 36; ++base, ++i) {
|
||||
std::cout << "Base " << std::setw(2) << base << ':';
|
||||
for (auto digits : futures[i].get())
|
||||
std::cout << ' ' << digits;
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
3
Task/Repunit-primes/F-Sharp/repunit-primes.fs
Normal file
3
Task/Repunit-primes/F-Sharp/repunit-primes.fs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Repunit primes. Nigel Galloway: January 24th., 2022
|
||||
let rUnitP(b:int)=let b=bigint b in primes32()|>Seq.takeWhile((>)1000)|>Seq.map(fun n->(n,((b**n)-1I)/(b-1I)))|>Seq.filter(fun(_,n)->Open.Numeric.Primes.MillerRabin.IsProbablePrime &n)|>Seq.map fst
|
||||
[2..16]|>List.iter(fun n->printf $"Base %d{n}: "; rUnitP(n)|>Seq.iter(printf "%d "); printfn "")
|
||||
24
Task/Repunit-primes/Go/repunit-primes.go
Normal file
24
Task/Repunit-primes/Go/repunit-primes.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
big "github.com/ncw/gmp"
|
||||
"rcu"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
limit := 2700
|
||||
primes := rcu.Primes(limit)
|
||||
s := new(big.Int)
|
||||
for b := 2; b <= 36; b++ {
|
||||
var rPrimes []int
|
||||
for _, p := range primes {
|
||||
s.SetString(strings.Repeat("1", p), b)
|
||||
if s.ProbablyPrime(15) {
|
||||
rPrimes = append(rPrimes, p)
|
||||
}
|
||||
}
|
||||
fmt.Printf("Base %2d: %v\n", b, rPrimes)
|
||||
}
|
||||
}
|
||||
7
Task/Repunit-primes/Julia/repunit-primes.julia
Normal file
7
Task/Repunit-primes/Julia/repunit-primes.julia
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
using Primes
|
||||
|
||||
repunitprimeinbase(n, base) = isprime(evalpoly(BigInt(base), [1 for _ in 1:n]))
|
||||
|
||||
for b in 2:40
|
||||
println(rpad("Base $b:", 9), filter(n -> repunitprimeinbase(n, b), 1:2700))
|
||||
end
|
||||
9
Task/Repunit-primes/Mathematica/repunit-primes.math
Normal file
9
Task/Repunit-primes/Mathematica/repunit-primes.math
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
ClearAll[RepUnitPrimeQ]
|
||||
RepUnitPrimeQ[b_][n_] := PrimeQ[FromDigits[ConstantArray[1, n], b]]
|
||||
ClearAll[RepUnitPrimeQ]
|
||||
RepUnitPrimeQ[b_][n_] := PrimeQ[FromDigits[ConstantArray[1, n], b]]
|
||||
Do[
|
||||
Print["Base ", b, ": ", Select[Range[2700], RepUnitPrimeQ[b]]]
|
||||
,
|
||||
{b, 2, 16}
|
||||
]
|
||||
14
Task/Repunit-primes/Nim/repunit-primes.nim
Normal file
14
Task/Repunit-primes/Nim/repunit-primes.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import std/strformat
|
||||
import integers
|
||||
|
||||
for base in 2..16:
|
||||
stdout.write &"{base:>2}:"
|
||||
var rep = ""
|
||||
while true:
|
||||
rep.add '1'
|
||||
if rep.len > 2700: break
|
||||
if not rep.len.isPrime: continue
|
||||
let val = newInteger(rep, base)
|
||||
if val.isPrime():
|
||||
stdout.write ' ', rep.len
|
||||
echo()
|
||||
11
Task/Repunit-primes/Perl/repunit-primes.pl
Normal file
11
Task/Repunit-primes/Perl/repunit-primes.pl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use ntheory <is_prime fromdigits>;
|
||||
|
||||
my $limit = 1000;
|
||||
|
||||
print "Repunit prime digits (up to $limit) in:\n";
|
||||
|
||||
for my $base (2..16) {
|
||||
printf "Base %2d: %s\n", $base, join ' ', grep { is_prime $_ and is_prime fromdigits(('1'x$_), $base) and " $_" } 1..$limit
|
||||
}
|
||||
32
Task/Repunit-primes/Phix/repunit-primes.phix
Normal file
32
Task/Repunit-primes/Phix/repunit-primes.phix
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
(phixonline)-->
|
||||
<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;">procedure</span> <span style="color: #000000;">repunit</span><span style="color: #0000FF;">(</span><span style="color: #004080;">mpz</span> <span style="color: #000000;">z</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">base</span><span style="color: #0000FF;">=</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #7060A8;">mpz_set_si</span><span style="color: #0000FF;">(</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">n</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #7060A8;">mpz_mul_si</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;">base</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #7060A8;">mpz_add_si</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;">1</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
|
||||
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #008080;">constant</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">limit</span><span style="color: #0000FF;">,</span><span style="color: #000000;">blimit</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">JS</span><span style="color: #0000FF;">?{</span><span style="color: #000000;">400</span><span style="color: #0000FF;">,</span><span style="color: #000000;">16</span><span style="color: #0000FF;">}</span> <span style="color: #000080;font-style:italic;">-- 8.8s</span>
|
||||
<span style="color: #0000FF;">:{</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">16</span><span style="color: #0000FF;">})</span> <span style="color: #000080;font-style:italic;">-- 50.3s
|
||||
-- :{1000,36}) -- 4 min 20s
|
||||
-- :{2700,16}) -- 28 min 35s
|
||||
-- :{2700,36}) -- >patience</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">primes</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">limit</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">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;">for</span> <span style="color: #000000;">base</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #000000;">blimit</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">rprimes</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">primes</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">p</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">primes</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #000000;">repunit</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;">base</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">mpz_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">z</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">rprimes</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rprimes</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">))</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</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;">"Base %2d: %s\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">base</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rprimes</span><span style="color: #0000FF;">)})</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span>
|
||||
<!--
|
||||
3
Task/Repunit-primes/Python/repunit-primes.py
Normal file
3
Task/Repunit-primes/Python/repunit-primes.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from sympy import isprime
|
||||
for b in range(2, 17):
|
||||
print(b, [n for n in range(2, 1001) if isprime(n) and isprime(int('1'*n, base=b))])
|
||||
7
Task/Repunit-primes/Raku/repunit-primes.raku
Normal file
7
Task/Repunit-primes/Raku/repunit-primes.raku
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
my $limit = 2700;
|
||||
|
||||
say "Repunit prime digits (up to $limit) in:";
|
||||
|
||||
.put for (2..16).hyper(:1batch).map: -> $base {
|
||||
$base.fmt("Base %2d: ") ~ (1..$limit).grep(&is-prime).grep( (1 x *).parse-base($base).is-prime )
|
||||
}
|
||||
7
Task/Repunit-primes/Ruby/repunit-primes.rb
Normal file
7
Task/Repunit-primes/Ruby/repunit-primes.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require 'prime'
|
||||
require 'gmp'
|
||||
|
||||
(2..16).each do |base|
|
||||
res = Prime.each(1000).select {|n| GMP::Z(("1" * n).to_i(base)).probab_prime? > 0}
|
||||
puts "Base #{base}: #{res.join(" ")}"
|
||||
end
|
||||
42
Task/Repunit-primes/Scheme/repunit-primes-1.ss
Normal file
42
Task/Repunit-primes/Scheme/repunit-primes-1.ss
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
; Test whether any integer is a probable prime.
|
||||
(define prime<probably>?
|
||||
(lambda (n)
|
||||
; Fast modular exponentiation.
|
||||
(define modexpt
|
||||
(lambda (b e m)
|
||||
(cond
|
||||
((zero? e) 1)
|
||||
((even? e) (modexpt (mod (* b b) m) (div e 2) m))
|
||||
((odd? e) (mod (* b (modexpt b (- e 1) m)) m)))))
|
||||
; Return multiple values s, d such that d is odd and 2^s * d = n.
|
||||
(define split
|
||||
(lambda (n)
|
||||
(let recur ((s 0) (d n))
|
||||
(if (odd? d)
|
||||
(values s d)
|
||||
(recur (+ s 1) (div d 2))))))
|
||||
; Test whether the number a proves that n is composite.
|
||||
(define composite-witness?
|
||||
(lambda (n a)
|
||||
(let*-values (((s d) (split (- n 1)))
|
||||
((x) (modexpt a d n)))
|
||||
(and (not (= x 1))
|
||||
(not (= x (- n 1)))
|
||||
(let try ((r (- s 1)))
|
||||
(set! x (modexpt x 2 n))
|
||||
(or (zero? r)
|
||||
(= x 1)
|
||||
(and (not (= x (- n 1)))
|
||||
(try (- r 1)))))))))
|
||||
; Test whether n > 2 is a Miller-Rabin pseudoprime, k trials.
|
||||
(define pseudoprime?
|
||||
(lambda (n k)
|
||||
(or (zero? k)
|
||||
(let ((a (+ 2 (random (- n 2)))))
|
||||
(and (not (composite-witness? n a))
|
||||
(pseudoprime? n (- k 1)))))))
|
||||
; Compute and return Probable Primality using the Miller-Rabin algorithm.
|
||||
(and (> n 1)
|
||||
(or (= n 2)
|
||||
(and (odd? n)
|
||||
(pseudoprime? n 50))))))
|
||||
19
Task/Repunit-primes/Scheme/repunit-primes-2.ss
Normal file
19
Task/Repunit-primes/Scheme/repunit-primes-2.ss
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
; Return list of the Repunit Primes in the given base up to the given limit.
|
||||
(define repunit_primes
|
||||
(lambda (base limit)
|
||||
(let loop ((count 2)
|
||||
(value (1+ base)))
|
||||
(cond ((> count limit)
|
||||
'())
|
||||
((and (prime<probably>? count) (prime<probably>? value))
|
||||
(cons count (loop (1+ count) (+ value (expt base count)))))
|
||||
(else
|
||||
(loop (1+ count) (+ value (expt base count))))))))
|
||||
|
||||
; Show all the Repunit Primes up to 2700 digits for bases 2 through 16.
|
||||
(let ((max-base 16)
|
||||
(max-digits 2700))
|
||||
(printf "~%Repunit Primes up to ~d digits for bases 2 through ~d:~%" max-digits max-base)
|
||||
(do ((base 2 (1+ base)))
|
||||
((> base max-base))
|
||||
(printf "Base ~2d: ~a~%" base (repunit_primes base max-digits))))
|
||||
8
Task/Repunit-primes/Sidef/repunit-primes.sidef
Normal file
8
Task/Repunit-primes/Sidef/repunit-primes.sidef
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
var limit = 1000
|
||||
|
||||
say "Repunit prime digits (up to #{limit}) in:"
|
||||
|
||||
for n in (2..20) {
|
||||
printf("Base %2d: %s\n", n,
|
||||
{|k| is_prime((n**k - 1) / (n-1)) }.grep(1..limit))
|
||||
}
|
||||
18
Task/Repunit-primes/Wren/repunit-primes.wren
Normal file
18
Task/Repunit-primes/Wren/repunit-primes.wren
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* repunit_primes.wren */
|
||||
|
||||
import "./gmp" for Mpz
|
||||
import "./math" for Int
|
||||
import "./fmt" for Fmt
|
||||
import "./str" for Str
|
||||
|
||||
var limit = 2700
|
||||
var primes = Int.primeSieve(limit)
|
||||
|
||||
for (b in 2..36) {
|
||||
var rPrimes = []
|
||||
for (p in primes) {
|
||||
var s = Mpz.fromStr(Str.repeat("1", p), b)
|
||||
if (s.probPrime(15) > 0) rPrimes.add(p)
|
||||
}
|
||||
Fmt.print("Base $2d: $n", b, rPrimes)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue