Smarandache prime-digital sequence: Difference between revisions

C, C++ and Rust examples made a bit more ambitious
m (Removed extraneous space character)
(C, C++ and Rust examples made a bit more ambitious)
Line 179:
=={{header|C}}==
{{trans|C++}}
<lang c>#include <stdboollocale.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
 
typedef uint32_t integer;
uint32_t next_prime_digit_number(uint32_t n) {
 
uint32_tinteger next_prime_digit_number(uint32_tinteger n) {
if (n == 0)
return 2;
Line 197 ⟶ 200:
}
 
bool is_prime(uint32_tinteger n) {
if (n < 2)
return false;
Line 204 ⟶ 207:
if (n % 3 == 0)
return n == 3;
forif (uint32_tn p =% 5; p * p <= n; p += 40) {
ifreturn (n % p == 0)5;
static const integer wheel[] = { 4,2,4,2,4,6,2,6 };
return false;
integer p += 27;
iffor (n;;) % p == 0){
for (int i = return0; falsei < 8; ++i) {
if n % if (p ==* 0p {> n)
return true;
if (n % p +== 4;0)
return false;
returnp false+= wheel[i];
}
}
return true;
}
 
int main() {
setlocale(LC_ALL, "");
const uint32_tinteger limit = 100000001000000000;
uint32_t n = 0, n1 = 0, n2 = 0, n3 = 0;
integer n = 0, max = 0;
printf("First 25 SPDS primes:\n");
for (int i = 0; n < limit; ) {
Line 224 ⟶ 233:
if (i < 25) {
if (i > 0)
printf(", ");
printf("%'u", n);
}
else if (i == 25)
Line 231 ⟶ 240:
++i;
if (i == 100)
n1printf("Hundredth =SPDS prime: %'u\n", n);
else if (i == 1000)
n2printf("Thousandth =SPDS prime: %'u\n", n);
n3else if (i == n;10000)
printf("ThousandthTen thousandth SPDS prime: %'u\n", n2n);
max = n;
}
printf("HundredthLargest SPDS prime less than %'u: %'u\n", n1limit, max);
printf("Thousandth SPDS prime: %u\n", n2);
printf("Largest SPDS prime less than %u: %u\n", limit, n3);
return 0;
}</lang>
Line 245 ⟶ 254:
<pre>
First 25 SPDS primes:
2, 3, 5, 7, 23, 37, 53, 73, 223, 227, 233, 257, 277, 337, 353, 373, 523, 557, 577, 727, 733, 757, 773 2,237 22372, 2273273
Hundredth SPDS prime: 3322333,223
Thousandth SPDS prime: 32735273,273,527
LargestTen thousandth SPDS prime less than 10000000: 7777753273,322,727
printf("Largest SPDS prime less than %u1,000,000,000: %u\n"777, limit777, n3);773
</pre>
 
Line 278 ⟶ 288:
if (n % 3 == 0)
return n == 3;
forif (integern p =% 5; p * p <= n; p += 40) {
ifreturn (n % p == 0)5;
constexpr integer wheel[] = { 4,2,4,2,4,6,2,6 };
return false;
integer p += 27;
iffor (n;;) % p == 0){
for (integer w : returnwheel) false;{
if (p * p > n)
return true;
if (n % p == 0)
return false;
p += w;
true }
}
return true;
}
 
int main() {
std::cout.imbue(std::locale(""));
const integer limit = 10000000;
const integer n = 0, n1 = 0, n2 = 0, n3limit = 01000000000;
integer n = 0, max = 0;
std::cout << "First 25 SPDS primes:\n";
for (int i = 0; n < limit; ) {
Line 298 ⟶ 314:
if (i < 25) {
if (i > 0)
std::cout << ",' "';
std::cout << n;
}
Line 305 ⟶ 321:
++i;
if (i == 100)
n1std::cout =<< "Hundredth SPDS prime: " << n << '\n';
else if (i == 1000)
n2std::cout =<< "Thousandth SPDS prime: " << n << '\n';
n3else if (i == n;10000)
std::cout << "ThousandthTen thousandth SPDS prime: " << n2n << '\n';
max = n;
}
std::cout << "HundredthLargest SPDS prime less than " << limit << ": " << n1max << '\n';
std::cout << "Thousandth SPDS prime: " << n2 << '\n';
std::cout << "Largest SPDS prime less than " << limit << ": " << n3 << '\n';
return 0;
}</lang>
Line 319 ⟶ 335:
<pre>
First 25 SPDS primes:
2, 3, 5, 7, 23, 37, 53, 73, 223, 227, 233, 257, 277, 337, 353, 373, 523, 557, 577, 727, 733, 757, 773 2,237 22372, 2273273
Hundredth SPDS prime: 3322333,223
Thousandth SPDS prime: 32735273,273,527
LargestTen thousandth SPDS prime less than 10000000: 7777753273,322,727
Largest SPDS prime less than 1,000,000,000: 777,777,773
</pre>
 
Line 1,410 ⟶ 1,427:
return n == 3;
}
letif mutn p% 5 == 5;0 {
while p * p <=return n {== 5;
}
if n % p == 0 {
let mut p = return false7;
const WHEEL: [u32; 8] = [4, 2, 4, 2, 4, 6, 2, 6];
}
loop p += 2;{
iffor nw %in p == 0&WHEEL {
returnif false;p * p > n {
return true;
}
if n % p == 0 {
return false;
}
p += w;
}
p += 4;
}
true
}
 
Line 1,449 ⟶ 1,470:
 
fn main() {
let limit = 100000001000000000;
let mut seq = smarandache_prime_digital_sequence().take_while(|x| *x < limit);
println!("First 25 SPDS primes:");
Line 1,461 ⟶ 1,482:
if let Some(p) = seq.by_ref().nth(999 - 100) {
println!("1000th SPDS prime: {}", p);
}
if let Some(p) = seq.by_ref().nth(9999 - 1000) {
println!("10,000th SPDS prime: {}", p);
}
if let Some(p) = seq.last() {
Line 1,473 ⟶ 1,497:
100th SPDS prime: 33223
1000th SPDS prime: 3273527
Largest10,000th SPDS prime less than 10000000: 7777753273322727
Largest SPDS prime less than 1000000000: 777777773
</pre>
 
1,777

edits