Use imported primes.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
pub struct CandidateGenerator {
|
pub struct CandidateGenerator {
|
||||||
base:u64,
|
base:u64,
|
||||||
|
// first use of the base
|
||||||
first_use:bool,
|
first_use:bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +30,27 @@ impl CandidateGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn calc_base(&mut self, last_prime:u64) {
|
||||||
|
if last_prime == 2 {
|
||||||
|
self.base = 0;
|
||||||
|
self.first_use = false;
|
||||||
|
} else if last_prime == 3 {
|
||||||
|
self.base = 6;
|
||||||
|
self.first_use = true;
|
||||||
|
} else {
|
||||||
|
let modulo = last_prime % 6;
|
||||||
|
if modulo == 1 {
|
||||||
|
self.base = last_prime + 5;
|
||||||
|
self.first_use = true;
|
||||||
|
} else if modulo == 5 {
|
||||||
|
self.base = last_prime + 1;
|
||||||
|
self.first_use = false;
|
||||||
|
} else {
|
||||||
|
panic!("Invalid last prime {}" , last_prime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn next(&mut self) -> u64 {
|
pub fn next(&mut self) -> u64 {
|
||||||
/*
|
/*
|
||||||
* All primes, except 2 and 3, will be equal to (n * 6 ± 1). This avoids
|
* All primes, except 2 and 3, will be equal to (n * 6 ± 1). This avoids
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ fn main() {
|
|||||||
println!("{}", res);
|
println!("{}", res);
|
||||||
} else {
|
} else {
|
||||||
let mut cand_gen = CandidateGenerator::new();
|
let mut cand_gen = CandidateGenerator::new();
|
||||||
|
if !primes_list.borrow().is_empty() {
|
||||||
|
cand_gen.calc_base(*primes_list.borrow().back().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let cand = cand_gen.next();
|
let cand = cand_gen.next();
|
||||||
|
|||||||
Reference in New Issue
Block a user