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 <
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
typedef uint32_t integer;
uint32_t next_prime_digit_number(uint32_t n) {▼
if (n == 0)
return 2;
Line 197 ⟶ 200:
}
bool is_prime(
if (n < 2)
return false;
Line 204 ⟶ 207:
if (n % 3 == 0)
return n == 3;
static const integer wheel[] = { 4,2,4,2,4,6,2,6 };
return false;▼
for (int i =
return true;
▲ return false;
}▼
}
▲ return true;
}
int main() {
setlocale(LC_ALL, "");
const
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)
else if (i == 1000)
max = n;
}
printf("
▲ 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
Hundredth SPDS prime:
Thousandth SPDS prime:
</pre>
Line 278 ⟶ 288:
if (n % 3 == 0)
return n == 3;
constexpr integer wheel[] = { 4,2,4,2,4,6,2,6 };
▲ return false;
for (integer w :
if (p * p > n)
return true;
if (n % p == 0)
return false;
p += w;
}
▲ return true;
}
int main() {
std::cout.imbue(std::locale(""));
const integer
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)
else if (i == 1000)
max = n;
}
std::cout << "
▲ std::cout << "Thousandth SPDS prime: " << n2 << '\n';
return 0;
}</lang>
Line 319 ⟶ 335:
<pre>
First 25 SPDS primes:
2
Hundredth SPDS prime:
Thousandth SPDS prime:
Largest SPDS prime less than 1,000,000,000: 777,777,773
</pre>
Line 1,410 ⟶ 1,427:
return n == 3;
}
}
▲ if n % p == 0 {
let mut p =
const WHEEL: [u32; 8] = [4, 2, 4, 2, 4, 6, 2, 6];
▲ }
loop
return true;
}
if n % p == 0 {
return false;
}
p += w;
}
▲ p += 4;
}
▲ true
}
Line 1,449 ⟶ 1,470:
fn main() {
let limit =
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
Largest SPDS prime less than 1000000000: 777777773
</pre>
|