Composite numbers k with no single digit factors whose factors are all substrings of k: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add C) |
m (rust example) |
||
Line 1,294: | Line 1,294: | ||
3129361 |
3129361 |
||
</pre> |
</pre> |
||
=={{header|Rust}}== |
|||
<syntaxhighlight lang="rust">use primes::{is_prime,factors_uniq}; |
|||
/// True if non-prime n's factors, all > 9, are all substrings of its representation in base 10 |
|||
fn contains_its_prime_factors_all_over_7(n: u64) -> bool { |
|||
if n < 10 || is_prime(n) { |
|||
return false; |
|||
} |
|||
let strn = &n.to_string(); |
|||
let pfacs = factors_uniq(n); |
|||
return pfacs.iter().all(|f| f > &9 && strn.contains(&f.to_string())); |
|||
} |
|||
fn main() { |
|||
let mut found = 0; |
|||
// 20 of these < 30 million |
|||
for n in 0..30_000_000 { |
|||
if contains_its_prime_factors_all_over_7(n) { |
|||
found += 1; |
|||
print!("{:12}{}", n, {if found % 10 == 0 {"\n"} else {""}}); |
|||
if found == 20 { |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
</syntaxhighlight>{{out}} |
|||
<pre> |
|||
15317 59177 83731 119911 183347 192413 1819231 2111317 2237411 3129361 |
|||
5526173 11610313 13436683 13731373 13737841 13831103 15813251 17692313 19173071 28118827 |
|||
</pre> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
<syntaxhighlight lang="ruby">var e = Enumerator({|f| |
<syntaxhighlight lang="ruby">var e = Enumerator({|f| |