Data update

This commit is contained in:
Ingy döt Net 2023-09-01 09:35:06 -07:00
parent 61b93a2cd1
commit 5af6d93694
858 changed files with 20572 additions and 2082 deletions

View file

@ -1,7 +1,6 @@
#include <cstdint>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <gmpxx.h>
typedef mpz_class integer;
@ -10,16 +9,10 @@ bool is_prime(const integer& n, int reps = 50) {
return mpz_probab_prime_p(n.get_mpz_t(), reps);
}
std::string to_string(const integer& n) {
std::ostringstream out;
out << n;
return out.str();
}
bool is_circular_prime(const integer& p) {
if (!is_prime(p))
return false;
std::string str(to_string(p));
std::string str = p.get_str();
for (size_t i = 0, n = str.size(); i + 1 < n; ++i) {
std::rotate(str.begin(), str.begin() + 1, str.end());
integer p2(str, 10);
@ -63,7 +56,7 @@ int main() {
std::cout << '\n';
std::cout << "Next 4 circular primes:\n";
p = next_repunit(p);
std::string str(to_string(p));
std::string str = p.get_str();
int digits = str.size();
for (int count = 0; count < 4; ) {
if (is_prime(p, 15)) {

View file

@ -0,0 +1,67 @@
begin globals
_last1 = 7
CFTimeInterval t
byte n(_last1 +1) //array of digits
uint64 list(20), p10 = 1
short count, digits, first1 = _last1
n(_last1) = 2 //First number to check
end globals
local fn convertToNumber as uint64
short i = first1
uint64 nr = n(i)
while i < _last1
i++ : nr = nr * 10 + n(i)
wend
end fn = nr
void local fn increment( dgt as short )
select n(dgt)
case 1, 7, 5 : n(dgt) += 2
case 3 : if digits then n(dgt) = 7 else n(dgt) = 5
case 9 : n(dgt) = 1
if dgt == first1 then first1-- : digits++ : p10 *= 10
fn increment( dgt -1 )
case else : n(dgt)++
end select
end fn
local fn isPrime( v as uint64 ) as bool
if v < 4 then exit fn = yes
if v mod 3 == 0 then exit fn = no
uint64 f = 5
while f*f <= v
if v mod f == 0 then exit fn = no
f += 2
if v mod f == 0 then exit fn = no
f += 4
wend
end fn = yes
void local fn circularPrimes
uint64 num, nr
short r
while ( count < 19 )
num = fn convertToNumber
if fn isPrime( num )
nr = num
for r = 1 to digits
nr = 10 * ( nr mod p10 ) + ( nr / p10 ) //Rotate
if nr < num then break //Rotation of lower number
if fn isPrime( nr ) == no then break //Not prime
next
if r > digits then list( count ) = num : count++
end if
fn increment( _last1 )
wend
end fn
window 1, @"Circular Primes in FutureBasic", (0, 0, 280, 320)
t = fn CACurrentMediaTime
fn circularPrimes
t = fn CACurrentMediaTime - t
for count = 0 to 18
printf @"%22u",list(count)
next
printf @"\n Compute time: %.3f ms", t * 1000
handleevents