Debian Codegraph @

tests/by-util/test_factor.rs

raw
1 // This file is part of the uutils coreutils package.
2 //
3 // For the full copyright and license information, please view the LICENSE
4 // file that was distributed with this source code.
5
6 // spell-checker:ignore (methods) hexdigest funcs nprimes cmdline
7 #![allow(
8 clippy::similar_names,
9 clippy::cast_possible_truncation,
10 clippy::cast_sign_loss
11 )]
12
13 use uutests::new_ucmd;
14
15 use std::fmt::Write;
16 use std::time::{Duration, SystemTime};
17
18 use rand::{
19 RngExt as _, SeedableRng,
20 distr::{Distribution, Uniform},
21 rngs::SmallRng,
22 };
23
24 const NUM_PRIMES: usize = 10000;
25 const NUM_TESTS: usize = 100;
26
27 #[test]
28 fn test_invalid_arg() {
29 new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
30 }
31
32 #[test]
33 fn test_invalid_negative_arg_shows_tip() {
34 // Test that factor shows a tip when given an invalid negative argument
35 // Test that "-1" is not misinterpreted as an invalid option
36 new_ucmd!()
37 .arg("-1")
38 .fails()
39 .code_is(1)
40 .stderr_contains("unexpected argument '-1' found")
41 .stderr_contains("tip: to pass '-1' as a value, use '-- -1'")
42 .stderr_contains("Usage: factor");
43 }
44
45 #[test]
46 fn test_valid_arg_exponents() {
47 new_ucmd!().arg("-h").succeeds();
48 new_ucmd!().arg("--exponents").succeeds();
49 }
50
51 #[test]
52 fn test_repeated_exponents() {
53 new_ucmd!()
54 .args(&["-hh", "1234", "10240"])
55 .succeeds()
56 .stdout_only("1234: 2 617\n10240: 2^11 5\n")
57 .no_stderr();
58 }
59
60 #[test]
61 fn test_trim_null_chars() {
62 new_ucmd!()
63 .pipe_in("42\0")
64 .succeeds()
65 .stdout_only("42: 2 3 7\n")
66 .no_stderr();
67 }
68
69 #[test]
70 #[cfg(feature = "sort")]
71 #[cfg(not(target_os = "android"))]
72 #[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
73 fn test_parallel() {
74 use hex_literal::hex;
75 use sha1::{Digest, Sha1};
76 use std::fs::OpenOptions;
77 use tempfile::TempDir;
78 use uutests::{
79 util::{AtPath, TestScenario},
80 util_name,
81 };
82 // factor should only flush the buffer at line breaks
83 let n_integers = 50_000;
84 let mut input_string = String::with_capacity(n_integers * 6);
85 for i in 0..=n_integers {
86 let _ = write!(input_string, "{i} ");
87 }
88
89 let tmp_dir = TempDir::new().unwrap();
90 let tmp_dir = AtPath::new(tmp_dir.path());
91 tmp_dir.touch("output");
92 let output = OpenOptions::new()
93 .append(true)
94 .open(tmp_dir.plus("output"))
95 .unwrap();
96
97 for child in (0..8)
98 .map(|_| {
99 new_ucmd!()
100 .set_stdout(output.try_clone().unwrap())
101 .pipe_in(input_string.clone())
102 .run_no_wait()
103 })
104 .collect::<Vec<_>>()
105 {
106 child.wait().unwrap().success();
107 }
108
109 let result = TestScenario::new(util_name!())
110 .ccmd("sort")
111 .arg(tmp_dir.plus("output"))
112 .succeeds();
113 let mut hasher = Sha1::new();
114 hasher.update(result.stdout());
115 let hash_check = hasher.finalize();
116 assert_eq!(
117 hash_check[..],
118 hex!("73f104b140449feac7ccf27b4c13ef6b9a4c5ee4")
119 );
120 }
121
122 #[test]
123 fn test_first_1000_integers() {
124 use hex_literal::hex;
125 use sha1::{Digest, Sha1};
126
127 let n_integers = 1000;
128 let mut input_string = String::new();
129 for i in 0..=n_integers {
130 let _ = write!(input_string, "{i} ");
131 }
132
133 println!("STDIN='{input_string}'");
134 let result = new_ucmd!().pipe_in(input_string.as_bytes()).succeeds();
135
136 // `seq 0 1000 | factor | sha1sum` => "c734327bd18b90fca5762f671672b5eda19f7dca"
137 let mut hasher = Sha1::new();
138 hasher.update(result.stdout());
139 let hash_check = hasher.finalize();
140 assert_eq!(
141 hash_check[..],
142 hex!("c734327bd18b90fca5762f671672b5eda19f7dca")
143 );
144 }
145
146 #[test]
147 fn test_first_1000_integers_with_exponents() {
148 use hex_literal::hex;
149 use sha1::{Digest, Sha1};
150
151 let n_integers = 1000;
152 let mut input_string = String::new();
153 for i in 0..=n_integers {
154 let _ = write!(input_string, "{i} ");
155 }
156
157 println!("STDIN='{input_string}'");
158 let result = new_ucmd!()
159 .arg("-h")
160 .pipe_in(input_string.as_bytes())
161 .succeeds();
162
163 // Known factorizations for verification
164 // `seq 0 1000 | factor -h | sha1sum` => "45f5f758a9319870770bd1fec2de23d54331944d"
165 let mut hasher = Sha1::new();
166 hasher.update(result.stdout());
167 let hash_check = hasher.finalize();
168 assert_eq!(
169 hash_check[..],
170 hex!("45f5f758a9319870770bd1fec2de23d54331944d")
171 );
172 }
173 #[test]
174 fn test_cli_args() {
175 // Make sure that factor works with CLI arguments as well.
176 new_ucmd!().args(&["3"]).succeeds().stdout_contains("3: 3");
177
178 new_ucmd!()
179 .args(&["3", "6", " +9"])
180 .succeeds()
181 .stdout_contains("3: 3")
182 .stdout_contains("9: 3 3");
183 }
184
185 #[test]
186 fn test_random() {
187 let log_num_primes = f64::from(u32::try_from(NUM_PRIMES).unwrap()).log2().ceil();
188 let primes = num_prime::nt_funcs::nprimes(NUM_PRIMES);
189
190 let rng_seed = SystemTime::now()
191 .duration_since(SystemTime::UNIX_EPOCH)
192 .unwrap()
193 .as_secs();
194 println!("rng_seed={rng_seed:?}");
195 let mut rng = SmallRng::seed_from_u64(rng_seed);
196
197 let mut rand_gt = move |min: u64| {
198 let mut product = 1_u64;
199 let mut factors = Vec::new();
200 while product < min {
201 // log distribution---higher probability for lower numbers
202 let factor = loop {
203 let next = rng.random_range(0_f64..log_num_primes).exp2().floor() as usize;
204 if next < NUM_PRIMES {
205 break primes[next];
206 }
207 };
208
209 match product.checked_mul(factor) {
210 Some(p) => {
211 product = p;
212 factors.push(factor);
213 }
214 None => break,
215 }
216 }
217
218 factors.sort_unstable();
219 (product, factors)
220 };
221
222 // build an input and expected output string from factor
223 let mut input_string = String::new();
224 let mut output_string = String::new();
225 for _ in 0..NUM_TESTS {
226 let (product, factors) = rand_gt(1 << 63);
227 let _ = write!(input_string, "{product} ");
228
229 let _ = write!(output_string, "{product}:");
230 for factor in factors {
231 let _ = write!(output_string, " {factor}");
232 }
233 output_string.push('\n');
234 }
235
236 run(input_string.as_bytes(), output_string.as_bytes());
237 }
238
239 #[test]
240 fn test_random_big() {
241 let rng_seed = SystemTime::now()
242 .duration_since(SystemTime::UNIX_EPOCH)
243 .unwrap()
244 .as_secs();
245 println!("rng_seed={rng_seed:?}");
246 let mut rng = SmallRng::seed_from_u64(rng_seed);
247
248 let bit_range_1 = Uniform::new(14, 51).unwrap();
249 let mut rand_64 = move || {
250 // first, choose a random number of bits for the first factor
251 let f_bit_1 = bit_range_1.sample(&mut rng);
252 // how many more bits do we need?
253 let rem = 64 - f_bit_1;
254
255 // we will have a number of additional factors equal to n_facts + 1
256 // where n_facts is in [0, floor(rem/14) ) NOTE half-open interval
257 // Each prime factor is at least 14 bits, hence floor(rem/14)
258 let n_factors = Uniform::new(0, rem / 14).unwrap().sample(&mut rng);
259 // we have to distribute extra_bits among the (n_facts + 1) values
260 let extra_bits = rem - (n_factors + 1) * 14;
261 // (remember, a Range is a half-open interval)
262 let extra_range = Uniform::new(0, extra_bits + 1).unwrap();
263
264 // to generate an even split of this range, generate n-1 random elements
265 // in the range, add the desired total value to the end, sort this list,
266 // and then compute the sequential differences.
267 let mut f_bits = Vec::with_capacity(n_factors + 1);
268 for _ in 0..n_factors {
269 f_bits.push(extra_range.sample(&mut rng));
270 }
271 f_bits.push(extra_bits);
272 f_bits.sort_unstable();
273
274 // compute sequential differences here. We leave off the +14 bits
275 // so we can just index PRIMES_BY_BITS
276 let mut f_bits = f_bits
277 .iter()
278 .scan(0, |st, &x| {
279 let ret = x - *st; // + 14 would give actual number of bits
280 *st = x;
281 Some(ret)
282 })
283 .collect::<Vec<usize>>();
284 // finally, add f_bit_1 in there
285 f_bits.push(f_bit_1 - 14); // index of f_bit_1 in PRIMES_BY_BITS
286 let f_bits = f_bits;
287
288 let mut n_bits = 0;
289 let mut product = 1_u64;
290 let mut factors = Vec::with_capacity(f_bits.len());
291 for bit in f_bits {
292 assert!(bit < 37);
293 n_bits += 14 + bit;
294 let elm = Uniform::new(0, PRIMES_BY_BITS[bit].len())
295 .unwrap()
296 .sample(&mut rng);
297 let factor = PRIMES_BY_BITS[bit][elm];
298 factors.push(factor);
299 product *= factor;
300 }
301 assert_eq!(n_bits, 64);
302
303 factors.sort_unstable();
304 (product, factors)
305 };
306
307 let mut input_string = String::new();
308 let mut output_string = String::new();
309 for _ in 0..NUM_TESTS {
310 let (product, factors) = rand_64();
311 let _ = write!(input_string, "{product} ");
312
313 let _ = write!(output_string, "{product}:");
314 for factor in factors {
315 let _ = write!(output_string, " {factor}");
316 }
317 output_string.push('\n');
318 }
319
320 run(input_string.as_bytes(), output_string.as_bytes());
321 }
322
323 #[test]
324 fn test_big_primes() {
325 let mut input_string = String::new();
326 let mut output_string = String::new();
327 for prime in PRIMES64 {
328 let _ = write!(input_string, "{prime} ");
329 let _ = writeln!(output_string, "{prime}: {prime}");
330 }
331
332 run(input_string.as_bytes(), output_string.as_bytes());
333 }
334
335 fn run(input_string: &[u8], output_string: &[u8]) {
336 println!("STDIN='{}'", String::from_utf8_lossy(input_string));
337 println!(
338 "STDOUT(expected)='{}'",
339 String::from_utf8_lossy(output_string)
340 );
341 // now run factor
342 new_ucmd!()
343 .timeout(Duration::from_secs(240))
344 .pipe_in(input_string)
345 .succeeds()
346 .stdout_is(String::from_utf8(output_string.to_owned()).unwrap());
347 }
348
349 #[test]
350 fn test_primes_with_exponents() {
351 let mut input_string = String::new();
352 let mut output_string = String::new();
353 for primes in PRIMES_BY_BITS {
354 for &prime in *primes {
355 let _ = write!(input_string, "{prime} ");
356 let _ = writeln!(output_string, "{prime}: {prime}");
357 }
358 }
359
360 println!(
361 "STDIN='{}'",
362 String::from_utf8_lossy(input_string.as_bytes())
363 );
364 println!(
365 "STDOUT(expected)='{}'",
366 String::from_utf8_lossy(output_string.as_bytes())
367 );
368
369 // run factor with --exponents
370 new_ucmd!()
371 .timeout(Duration::from_secs(240))
372 .arg("--exponents")
373 .pipe_in(input_string)
374 .succeeds()
375 .stdout_is(String::from_utf8(output_string.as_bytes().to_owned()).unwrap());
376 }
377
378 #[test]
379 fn fails_on_invalid_number() {
380 new_ucmd!().arg("not-a-valid-number").fails();
381 new_ucmd!()
382 .arg("not-a-valid-number")
383 .arg("12")
384 .fails()
385 .stdout_contains("12: 2 2 3");
386 }
387
388 #[test]
389 #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
390 fn short_circuit_write_error() {
391 use std::fs::OpenOptions;
392
393 // Check that the error is printed exactly once and factor does not move on
394 // to the next number when a write error happens.
395 //
396 // Note: Technically, GNU prints the error twice, not because it does not
397 // short circuit the error, but because it always prints the error twice,
398 // for any number of inputs. That's silly behavior and printing once is
399 // clearly better.
400 let f = OpenOptions::new().write(true).open("/dev/full").unwrap();
401 new_ucmd!()
402 .arg("12")
403 .arg("10")
404 .set_stdout(f)
405 .fails()
406 .stderr_is("factor: write error: No space left on device\n");
407 }
408
409 const PRIMES_BY_BITS: &[&[u64]] = &[
410 PRIMES14, PRIMES15, PRIMES16, PRIMES17, PRIMES18, PRIMES19, PRIMES20, PRIMES21, PRIMES22,
411 PRIMES23, PRIMES24, PRIMES25, PRIMES26, PRIMES27, PRIMES28, PRIMES29, PRIMES30, PRIMES31,
412 PRIMES32, PRIMES33, PRIMES34, PRIMES35, PRIMES36, PRIMES37, PRIMES38, PRIMES39, PRIMES40,
413 PRIMES41, PRIMES42, PRIMES43, PRIMES44, PRIMES45, PRIMES46, PRIMES47, PRIMES48, PRIMES49,
414 PRIMES50,
415 ];
416
417 const PRIMES64: &[u64] = &[
418 18_446_744_073_709_551_557,
419 18_446_744_073_709_551_533,
420 18_446_744_073_709_551_521,
421 18_446_744_073_709_551_437,
422 18_446_744_073_709_551_427,
423 18_446_744_073_709_551_359,
424 18_446_744_073_709_551_337,
425 18_446_744_073_709_551_293,
426 18_446_744_073_709_551_263,
427 18_446_744_073_709_551_253,
428 18_446_744_073_709_551_191,
429 18_446_744_073_709_551_163,
430 18_446_744_073_709_551_113,
431 18_446_744_073_709_550_873,
432 18_446_744_073_709_550_791,
433 18_446_744_073_709_550_773,
434 18_446_744_073_709_550_771,
435 18_446_744_073_709_550_719,
436 18_446_744_073_709_550_717,
437 18_446_744_073_709_550_681,
438 18_446_744_073_709_550_671,
439 18_446_744_073_709_550_593,
440 18_446_744_073_709_550_591,
441 18_446_744_073_709_550_539,
442 18_446_744_073_709_550_537,
443 18_446_744_073_709_550_381,
444 18_446_744_073_709_550_341,
445 18_446_744_073_709_550_293,
446 18_446_744_073_709_550_237,
447 18_446_744_073_709_550_147,
448 18_446_744_073_709_550_141,
449 18_446_744_073_709_550_129,
450 18_446_744_073_709_550_111,
451 18_446_744_073_709_550_099,
452 18_446_744_073_709_550_047,
453 18_446_744_073_709_550_033,
454 18_446_744_073_709_550_009,
455 18_446_744_073_709_549_951,
456 18_446_744_073_709_549_861,
457 18_446_744_073_709_549_817,
458 18_446_744_073_709_549_811,
459 18_446_744_073_709_549_777,
460 18_446_744_073_709_549_757,
461 18_446_744_073_709_549_733,
462 18_446_744_073_709_549_667,
463 18_446_744_073_709_549_621,
464 18_446_744_073_709_549_613,
465 18_446_744_073_709_549_583,
466 18_446_744_073_709_549_571,
467 ];
468
469 const PRIMES14: &[u64] = &[
470 16381, 16369, 16363, 16361, 16349, 16339, 16333, 16319, 16301, 16273, 16267, 16253, 16249,
471 16231, 16229, 16223, 16217, 16193, 16189, 16187, 16183, 16141, 16139, 16127, 16111, 16103,
472 16097, 16091, 16087, 16073, 16069, 16067, 16063, 16061, 16057, 16033, 16007, 16001, 15991,
473 15973, 15971, 15959, 15937, 15923, 15919, 15913, 15907, 15901, 15889, 15887, 15881, 15877,
474 15859, 15823, 15817, 15809, 15803, 15797, 15791, 15787, 15773, 15767, 15761, 15749, 15739,
475 15737, 15733, 15731, 15727, 15683, 15679, 15671, 15667, 15661, 15649, 15647, 15643, 15641,
476 15629, 15619, 15607, 15601, 15583, 15581, 15569, 15559, 15551, 15541, 15527, 15511, 15497,
477 15493, 15473, 15467, 15461, 15451, 15443, 15439, 15427, 15413, 15401, 15391, 15383, 15377,
478 15373,
479 ];
480
481 const PRIMES15: &[u64] = &[
482 32749, 32719, 32717, 32713, 32707, 32693, 32687, 32653, 32647, 32633, 32621, 32611, 32609,
483 32603, 32587, 32579, 32573, 32569, 32563, 32561, 32537, 32533, 32531, 32507, 32503, 32497,
484 32491, 32479, 32467, 32443, 32441, 32429, 32423, 32413, 32411, 32401, 32381, 32377, 32371,
485 32369, 32363, 32359, 32353, 32341, 32327, 32323, 32321, 32309, 32303, 32299, 32297, 32261,
486 32257, 32251, 32237, 32233, 32213, 32203, 32191, 32189, 32183, 32173, 32159, 32143, 32141,
487 32119, 32117, 32099, 32089, 32083, 32077, 32069, 32063, 32059, 32057, 32051, 32029, 32027,
488 32009, 32003, 31991, 31981, 31973, 31963, 31957, 31907, 31891, 31883, 31873, 31859, 31849,
489 31847, 31817, 31799, 31793, 31771, 31769, 31751,
490 ];
491
492 const PRIMES16: &[u64] = &[
493 65521, 65519, 65497, 65479, 65449, 65447, 65437, 65423, 65419, 65413, 65407, 65393, 65381,
494 65371, 65357, 65353, 65327, 65323, 65309, 65293, 65287, 65269, 65267, 65257, 65239, 65213,
495 65203, 65183, 65179, 65173, 65171, 65167, 65147, 65141, 65129, 65123, 65119, 65111, 65101,
496 65099, 65089, 65071, 65063, 65053, 65033, 65029, 65027, 65011, 65003, 64997, 64969, 64951,
497 64937, 64927, 64921, 64919, 64901, 64891, 64879, 64877, 64871, 64853, 64849, 64817, 64811,
498 64793, 64783, 64781, 64763, 64747, 64717, 64709, 64693, 64679, 64667, 64663, 64661, 64633,
499 64627, 64621, 64613, 64609, 64601, 64591, 64579, 64577, 64567, 64553,
500 ];
501
502 const PRIMES17: &[u64] = &[
503 131_071, 131_063, 131_059, 131_041, 131_023, 131_011, 131_009, 130_987, 130_981, 130_973,
504 130_969, 130_957, 130_927, 130_873, 130_859, 130_843, 130_841, 130_829, 130_817, 130_811,
505 130_807, 130_787, 130_783, 130_769, 130_729, 130_699, 130_693, 130_687, 130_681, 130_657,
506 130_651, 130_649, 130_643, 130_639, 130_633, 130_631, 130_621, 130_619, 130_589, 130_579,
507 130_553, 130_547, 130_531, 130_523, 130_517, 130_513, 130_489, 130_483, 130_477, 130_469,
508 130_457, 130_447, 130_439, 130_423, 130_411, 130_409, 130_399, 130_379, 130_369, 130_367,
509 130_363, 130_349, 130_343, 130_337, 130_307, 130_303, 130_279, 130_267, 130_261, 130_259,
510 130_253, 130_241, 130_223, 130_211, 130_201, 130_199, 130_183, 130_171, 130_147, 130_127,
511 130_121, 130_099, 130_087, 130_079, 130_073, 130_069, 130_057, 130_051,
512 ];
513
514 const PRIMES18: &[u64] = &[
515 262_139, 262_133, 262_127, 262_121, 262_111, 262_109, 262_103, 262_079, 262_069, 262_051,
516 262_049, 262_027, 262_007, 261_983, 261_977, 261_973, 261_971, 261_959, 261_917, 261_887,
517 261_881, 261_847, 261_823, 261_799, 261_791, 261_787, 261_773, 261_761, 261_757, 261_739,
518 261_721, 261_713, 261_707, 261_697, 261_673, 261_643, 261_641, 261_637, 261_631, 261_619,
519 261_601, 261_593, 261_587, 261_581, 261_577, 261_563, 261_557, 261_529, 261_523, 261_509,
520 261_467, 261_463, 261_451, 261_439, 261_433, 261_431, 261_427, 261_407, 261_389, 261_379,
521 261_353, 261_347, 261_337, 261_329, 261_323, 261_301, 261_281, 261_271, 261_251, 261_241,
522 261_229, 261_223, 261_169, 261_167, 261_127,
523 ];
524
525 const PRIMES19: &[u64] = &[
526 524_287, 524_269, 524_261, 524_257, 524_243, 524_231, 524_221, 524_219, 524_203, 524_201,
527 524_197, 524_189, 524_171, 524_149, 524_123, 524_119, 524_113, 524_099, 524_087, 524_081,
528 524_071, 524_063, 524_057, 524_053, 524_047, 523_997, 523_987, 523_969, 523_949, 523_937,
529 523_927, 523_907, 523_903, 523_877, 523_867, 523_847, 523_829, 523_801, 523_793, 523_777,
530 523_771, 523_763, 523_759, 523_741, 523_729, 523_717, 523_681, 523_673, 523_669, 523_667,
531 523_657, 523_639, 523_637, 523_631, 523_603, 523_597, 523_577, 523_573, 523_571, 523_553,
532 523_543, 523_541, 523_519, 523_511, 523_493, 523_489, 523_487, 523_463, 523_459, 523_433,
533 523_427, 523_417, 523_403, 523_387, 523_357, 523_351, 523_349, 523_333, 523_307, 523_297,
534 ];
535
536 const PRIMES20: &[u64] = &[
537 1_048_573, 1_048_571, 1_048_559, 1_048_549, 1_048_517, 1_048_507, 1_048_447, 1_048_433,
538 1_048_423, 1_048_391, 1_048_387, 1_048_367, 1_048_361, 1_048_357, 1_048_343, 1_048_309,
539 1_048_291, 1_048_273, 1_048_261, 1_048_219, 1_048_217, 1_048_213, 1_048_193, 1_048_189,
540 1_048_139, 1_048_129, 1_048_127, 1_048_123, 1_048_063, 1_048_051, 1_048_049, 1_048_043,
541 1_048_027, 1_048_013, 1_048_009, 1_048_007, 1_047_997, 1_047_989, 1_047_979, 1_047_971,
542 1_047_961, 1_047_941, 1_047_929, 1_047_923, 1_047_887, 1_047_883, 1_047_881, 1_047_859,
543 1_047_841, 1_047_833, 1_047_821, 1_047_779, 1_047_773, 1_047_763, 1_047_751, 1_047_737,
544 1_047_721, 1_047_713, 1_047_703, 1_047_701, 1_047_691, 1_047_689, 1_047_671, 1_047_667,
545 1_047_653, 1_047_649, 1_047_647, 1_047_589, 1_047_587, 1_047_559,
546 ];
547
548 const PRIMES21: &[u64] = &[
549 2_097_143, 2_097_133, 2_097_131, 2_097_097, 2_097_091, 2_097_083, 2_097_047, 2_097_041,
550 2_097_031, 2_097_023, 2_097_013, 2_096_993, 2_096_987, 2_096_971, 2_096_959, 2_096_957,
551 2_096_947, 2_096_923, 2_096_911, 2_096_909, 2_096_893, 2_096_881, 2_096_873, 2_096_867,
552 2_096_851, 2_096_837, 2_096_807, 2_096_791, 2_096_789, 2_096_777, 2_096_761, 2_096_741,
553 2_096_737, 2_096_713, 2_096_693, 2_096_687, 2_096_681, 2_096_639, 2_096_629, 2_096_621,
554 2_096_599, 2_096_597, 2_096_569, 2_096_539, 2_096_533, 2_096_483, 2_096_449, 2_096_431,
555 2_096_429, 2_096_411, 2_096_407, 2_096_401, 2_096_399, 2_096_377, 2_096_357, 2_096_291,
556 2_096_273, 2_096_261, 2_096_233, 2_096_231, 2_096_221, 2_096_209, 2_096_191, 2_096_183,
557 2_096_147,
558 ];
559
560 const PRIMES22: &[u64] = &[
561 4_194_301, 4_194_287, 4_194_277, 4_194_271, 4_194_247, 4_194_217, 4_194_199, 4_194_191,
562 4_194_187, 4_194_181, 4_194_173, 4_194_167, 4_194_143, 4_194_137, 4_194_131, 4_194_107,
563 4_194_103, 4_194_023, 4_194_011, 4_194_007, 4_193_977, 4_193_971, 4_193_963, 4_193_957,
564 4_193_939, 4_193_929, 4_193_909, 4_193_869, 4_193_807, 4_193_803, 4_193_801, 4_193_789,
565 4_193_759, 4_193_753, 4_193_743, 4_193_701, 4_193_663, 4_193_633, 4_193_573, 4_193_569,
566 4_193_551, 4_193_549, 4_193_531, 4_193_513, 4_193_507, 4_193_459, 4_193_447, 4_193_443,
567 4_193_417, 4_193_411, 4_193_393, 4_193_389, 4_193_381, 4_193_377, 4_193_369, 4_193_359,
568 4_193_353, 4_193_327, 4_193_309, 4_193_303, 4_193_297,
569 ];
570
571 const PRIMES23: &[u64] = &[
572 8_388_593, 8_388_587, 8_388_581, 8_388_571, 8_388_547, 8_388_539, 8_388_473, 8_388_461,
573 8_388_451, 8_388_449, 8_388_439, 8_388_427, 8_388_421, 8_388_409, 8_388_377, 8_388_371,
574 8_388_319, 8_388_301, 8_388_287, 8_388_283, 8_388_277, 8_388_239, 8_388_209, 8_388_187,
575 8_388_113, 8_388_109, 8_388_091, 8_388_071, 8_388_059, 8_388_019, 8_388_013, 8_387_999,
576 8_387_993, 8_387_959, 8_387_957, 8_387_947, 8_387_933, 8_387_921, 8_387_917, 8_387_891,
577 8_387_879, 8_387_867, 8_387_861, 8_387_857, 8_387_839, 8_387_831, 8_387_809, 8_387_807,
578 8_387_741, 8_387_737, 8_387_723, 8_387_707, 8_387_671, 8_387_611, 8_387_609, 8_387_591,
579 ];
580
581 const PRIMES24: &[u64] = &[
582 16_777_213, 16_777_199, 16_777_183, 16_777_153, 16_777_141, 16_777_139, 16_777_127, 16_777_121,
583 16_777_099, 16_777_049, 16_777_027, 16_776_989, 16_776_973, 16_776_971, 16_776_967, 16_776_961,
584 16_776_941, 16_776_937, 16_776_931, 16_776_919, 16_776_901, 16_776_899, 16_776_869, 16_776_857,
585 16_776_839, 16_776_833, 16_776_817, 16_776_763, 16_776_731, 16_776_719, 16_776_713, 16_776_691,
586 16_776_689, 16_776_679, 16_776_659, 16_776_631, 16_776_623, 16_776_619, 16_776_607, 16_776_593,
587 16_776_581, 16_776_547, 16_776_521, 16_776_491, 16_776_481, 16_776_469, 16_776_451, 16_776_401,
588 16_776_391, 16_776_379, 16_776_371, 16_776_367, 16_776_343, 16_776_337, 16_776_317, 16_776_313,
589 16_776_289, 16_776_217, 16_776_211,
590 ];
591
592 const PRIMES25: &[u64] = &[
593 33_554_393, 33_554_383, 33_554_371, 33_554_347, 33_554_341, 33_554_317, 33_554_291, 33_554_273,
594 33_554_267, 33_554_249, 33_554_239, 33_554_221, 33_554_201, 33_554_167, 33_554_159, 33_554_137,
595 33_554_123, 33_554_093, 33_554_083, 33_554_077, 33_554_051, 33_554_021, 33_554_011, 33_554_009,
596 33_553_999, 33_553_991, 33_553_969, 33_553_967, 33_553_909, 33_553_901, 33_553_879, 33_553_837,
597 33_553_799, 33_553_787, 33_553_771, 33_553_769, 33_553_759, 33_553_747, 33_553_739, 33_553_727,
598 33_553_697, 33_553_693, 33_553_679, 33_553_661, 33_553_657, 33_553_651, 33_553_649, 33_553_633,
599 33_553_613, 33_553_607, 33_553_577, 33_553_549, 33_553_547, 33_553_537, 33_553_519, 33_553_517,
600 33_553_511, 33_553_489, 33_553_463, 33_553_451, 33_553_417,
601 ];
602
603 const PRIMES26: &[u64] = &[
604 67_108_859, 67_108_837, 67_108_819, 67_108_777, 67_108_763, 67_108_757, 67_108_753, 67_108_747,
605 67_108_739, 67_108_729, 67_108_721, 67_108_709, 67_108_693, 67_108_669, 67_108_667, 67_108_661,
606 67_108_649, 67_108_633, 67_108_597, 67_108_579, 67_108_529, 67_108_511, 67_108_507, 67_108_493,
607 67_108_471, 67_108_463, 67_108_453, 67_108_439, 67_108_387, 67_108_373, 67_108_369, 67_108_351,
608 67_108_331, 67_108_313, 67_108_303, 67_108_289, 67_108_271, 67_108_219, 67_108_207, 67_108_201,
609 67_108_199, 67_108_187, 67_108_183, 67_108_177, 67_108_127, 67_108_109, 67_108_081, 67_108_049,
610 67_108_039, 67_108_037, 67_108_033, 67_108_009, 67_108_007, 67_108_003, 67_107_983, 67_107_977,
611 67_107_967, 67_107_941, 67_107_919, 67_107_913, 67_107_883, 67_107_881, 67_107_871, 67_107_863,
612 ];
613
614 const PRIMES27: &[u64] = &[
615 134_217_689,
616 134_217_649,
617 134_217_617,
618 134_217_613,
619 134_217_593,
620 134_217_541,
621 134_217_529,
622 134_217_509,
623 134_217_497,
624 134_217_493,
625 134_217_487,
626 134_217_467,
627 134_217_439,
628 134_217_437,
629 134_217_409,
630 134_217_403,
631 134_217_401,
632 134_217_367,
633 134_217_361,
634 134_217_353,
635 134_217_323,
636 134_217_301,
637 134_217_277,
638 134_217_257,
639 134_217_247,
640 134_217_221,
641 134_217_199,
642 134_217_173,
643 134_217_163,
644 134_217_157,
645 134_217_131,
646 134_217_103,
647 134_217_089,
648 134_217_079,
649 134_217_049,
650 134_217_047,
651 134_217_043,
652 134_217_001,
653 134_216_987,
654 134_216_947,
655 134_216_939,
656 134_216_933,
657 134_216_911,
658 134_216_899,
659 134_216_881,
660 134_216_869,
661 134_216_867,
662 134_216_861,
663 134_216_837,
664 134_216_827,
665 134_216_807,
666 134_216_801,
667 134_216_791,
668 134_216_783,
669 134_216_777,
670 134_216_759,
671 134_216_737,
672 134_216_729,
673 ];
674
675 const PRIMES28: &[u64] = &[
676 268_435_399,
677 268_435_367,
678 268_435_361,
679 268_435_337,
680 268_435_331,
681 268_435_313,
682 268_435_291,
683 268_435_273,
684 268_435_243,
685 268_435_183,
686 268_435_171,
687 268_435_157,
688 268_435_147,
689 268_435_133,
690 268_435_129,
691 268_435_121,
692 268_435_109,
693 268_435_091,
694 268_435_067,
695 268_435_043,
696 268_435_039,
697 268_435_033,
698 268_435_019,
699 268_435_009,
700 268_435_007,
701 268_434_997,
702 268_434_979,
703 268_434_977,
704 268_434_961,
705 268_434_949,
706 268_434_941,
707 268_434_937,
708 268_434_857,
709 268_434_841,
710 268_434_827,
711 268_434_821,
712 268_434_787,
713 268_434_781,
714 268_434_779,
715 268_434_773,
716 268_434_731,
717 268_434_721,
718 268_434_713,
719 268_434_707,
720 268_434_703,
721 268_434_697,
722 268_434_659,
723 268_434_623,
724 268_434_619,
725 268_434_581,
726 268_434_577,
727 268_434_563,
728 268_434_557,
729 268_434_547,
730 268_434_511,
731 268_434_499,
732 268_434_479,
733 268_434_461,
734 ];
735
736 const PRIMES29: &[u64] = &[
737 536_870_909,
738 536_870_879,
739 536_870_869,
740 536_870_849,
741 536_870_839,
742 536_870_837,
743 536_870_819,
744 536_870_813,
745 536_870_791,
746 536_870_779,
747 536_870_767,
748 536_870_743,
749 536_870_729,
750 536_870_723,
751 536_870_717,
752 536_870_701,
753 536_870_683,
754 536_870_657,
755 536_870_641,
756 536_870_627,
757 536_870_611,
758 536_870_603,
759 536_870_599,
760 536_870_573,
761 536_870_569,
762 536_870_563,
763 536_870_561,
764 536_870_513,
765 536_870_501,
766 536_870_497,
767 536_870_473,
768 536_870_401,
769 536_870_363,
770 536_870_317,
771 536_870_303,
772 536_870_297,
773 536_870_273,
774 536_870_267,
775 536_870_239,
776 536_870_233,
777 536_870_219,
778 536_870_171,
779 536_870_167,
780 536_870_153,
781 536_870_123,
782 536_870_063,
783 536_870_057,
784 536_870_041,
785 536_870_027,
786 536_869_999,
787 536_869_951,
788 536_869_943,
789 536_869_937,
790 536_869_919,
791 536_869_901,
792 536_869_891,
793 ];
794
795 const PRIMES30: &[u64] = &[
796 1_073_741_789,
797 1_073_741_783,
798 1_073_741_741,
799 1_073_741_723,
800 1_073_741_719,
801 1_073_741_717,
802 1_073_741_689,
803 1_073_741_671,
804 1_073_741_663,
805 1_073_741_651,
806 1_073_741_621,
807 1_073_741_567,
808 1_073_741_561,
809 1_073_741_527,
810 1_073_741_503,
811 1_073_741_477,
812 1_073_741_467,
813 1_073_741_441,
814 1_073_741_419,
815 1_073_741_399,
816 1_073_741_387,
817 1_073_741_381,
818 1_073_741_371,
819 1_073_741_329,
820 1_073_741_311,
821 1_073_741_309,
822 1_073_741_287,
823 1_073_741_237,
824 1_073_741_213,
825 1_073_741_197,
826 1_073_741_189,
827 1_073_741_173,
828 1_073_741_101,
829 1_073_741_077,
830 1_073_741_047,
831 1_073_740_963,
832 1_073_740_951,
833 1_073_740_933,
834 1_073_740_909,
835 1_073_740_879,
836 1_073_740_853,
837 1_073_740_847,
838 1_073_740_819,
839 1_073_740_807,
840 ];
841
842 const PRIMES31: &[u64] = &[
843 2_147_483_647,
844 2_147_483_629,
845 2_147_483_587,
846 2_147_483_579,
847 2_147_483_563,
848 2_147_483_549,
849 2_147_483_543,
850 2_147_483_497,
851 2_147_483_489,
852 2_147_483_477,
853 2_147_483_423,
854 2_147_483_399,
855 2_147_483_353,
856 2_147_483_323,
857 2_147_483_269,
858 2_147_483_249,
859 2_147_483_237,
860 2_147_483_179,
861 2_147_483_171,
862 2_147_483_137,
863 2_147_483_123,
864 2_147_483_077,
865 2_147_483_069,
866 2_147_483_059,
867 2_147_483_053,
868 2_147_483_033,
869 2_147_483_029,
870 2_147_482_951,
871 2_147_482_949,
872 2_147_482_943,
873 2_147_482_937,
874 2_147_482_921,
875 2_147_482_877,
876 2_147_482_873,
877 2_147_482_867,
878 2_147_482_859,
879 2_147_482_819,
880 2_147_482_817,
881 2_147_482_811,
882 2_147_482_801,
883 2_147_482_763,
884 2_147_482_739,
885 2_147_482_697,
886 2_147_482_693,
887 2_147_482_681,
888 2_147_482_663,
889 2_147_482_661,
890 ];
891
892 const PRIMES32: &[u64] = &[
893 4_294_967_291,
894 4_294_967_279,
895 4_294_967_231,
896 4_294_967_197,
897 4_294_967_189,
898 4_294_967_161,
899 4_294_967_143,
900 4_294_967_111,
901 4_294_967_087,
902 4_294_967_029,
903 4_294_966_997,
904 4_294_966_981,
905 4_294_966_943,
906 4_294_966_927,
907 4_294_966_909,
908 4_294_966_877,
909 4_294_966_829,
910 4_294_966_813,
911 4_294_966_769,
912 4_294_966_667,
913 4_294_966_661,
914 4_294_966_657,
915 4_294_966_651,
916 4_294_966_639,
917 4_294_966_619,
918 4_294_966_591,
919 4_294_966_583,
920 4_294_966_553,
921 4_294_966_477,
922 4_294_966_447,
923 4_294_966_441,
924 4_294_966_427,
925 4_294_966_373,
926 4_294_966_367,
927 4_294_966_337,
928 4_294_966_297,
929 ];
930
931 const PRIMES33: &[u64] = &[
932 8_589_934_583,
933 8_589_934_567,
934 8_589_934_543,
935 8_589_934_513,
936 8_589_934_487,
937 8_589_934_307,
938 8_589_934_291,
939 8_589_934_289,
940 8_589_934_271,
941 8_589_934_237,
942 8_589_934_211,
943 8_589_934_207,
944 8_589_934_201,
945 8_589_934_187,
946 8_589_934_151,
947 8_589_934_141,
948 8_589_934_139,
949 8_589_934_117,
950 8_589_934_103,
951 8_589_934_099,
952 8_589_934_091,
953 8_589_934_069,
954 8_589_934_049,
955 8_589_934_027,
956 8_589_934_007,
957 8_589_933_973,
958 8_589_933_971,
959 8_589_933_967,
960 8_589_933_931,
961 8_589_933_917,
962 8_589_933_907,
963 8_589_933_853,
964 8_589_933_827,
965 8_589_933_823,
966 8_589_933_787,
967 8_589_933_773,
968 8_589_933_733,
969 8_589_933_731,
970 8_589_933_721,
971 8_589_933_683,
972 8_589_933_647,
973 8_589_933_641,
974 8_589_933_637,
975 8_589_933_631,
976 8_589_933_629,
977 8_589_933_619,
978 8_589_933_601,
979 8_589_933_581,
980 ];
981
982 const PRIMES34: &[u64] = &[
983 17_179_869_143,
984 17_179_869_107,
985 17_179_869_071,
986 17_179_869_053,
987 17_179_869_041,
988 17_179_869_019,
989 17_179_868_999,
990 17_179_868_977,
991 17_179_868_957,
992 17_179_868_903,
993 17_179_868_899,
994 17_179_868_887,
995 17_179_868_879,
996 17_179_868_873,
997 17_179_868_869,
998 17_179_868_861,
999 17_179_868_843,
1000 17_179_868_833,
1001 17_179_868_809,
1002 17_179_868_807,
1003 17_179_868_777,
1004 17_179_868_759,
1005 17_179_868_729,
1006 17_179_868_711,
1007 17_179_868_683,
1008 17_179_868_681,
1009 17_179_868_597,
1010 17_179_868_549,
1011 17_179_868_543,
1012 17_179_868_521,
1013 17_179_868_513,
1014 17_179_868_479,
1015 17_179_868_443,
1016 17_179_868_437,
1017 17_179_868_429,
1018 17_179_868_383,
1019 17_179_868_369,
1020 17_179_868_357,
1021 17_179_868_353,
1022 17_179_868_351,
1023 17_179_868_333,
1024 17_179_868_317,
1025 17_179_868_309,
1026 17_179_868_297,
1027 17_179_868_287,
1028 17_179_868_249,
1029 17_179_868_243,
1030 17_179_868_183,
1031 ];
1032
1033 const PRIMES35: &[u64] = &[
1034 34_359_738_337,
1035 34_359_738_319,
1036 34_359_738_307,
1037 34_359_738_299,
1038 34_359_738_289,
1039 34_359_738_247,
1040 34_359_738_227,
1041 34_359_738_121,
1042 34_359_738_059,
1043 34_359_738_043,
1044 34_359_738_011,
1045 34_359_737_917,
1046 34_359_737_869,
1047 34_359_737_849,
1048 34_359_737_837,
1049 34_359_737_821,
1050 34_359_737_813,
1051 34_359_737_791,
1052 34_359_737_777,
1053 34_359_737_771,
1054 34_359_737_717,
1055 34_359_737_591,
1056 34_359_737_567,
1057 34_359_737_549,
1058 34_359_737_519,
1059 34_359_737_497,
1060 34_359_737_479,
1061 34_359_737_407,
1062 34_359_737_393,
1063 34_359_737_371,
1064 ];
1065
1066 const PRIMES36: &[u64] = &[
1067 68_719_476_731,
1068 68_719_476_719,
1069 68_719_476_713,
1070 68_719_476_671,
1071 68_719_476_619,
1072 68_719_476_599,
1073 68_719_476_577,
1074 68_719_476_563,
1075 68_719_476_547,
1076 68_719_476_503,
1077 68_719_476_493,
1078 68_719_476_479,
1079 68_719_476_433,
1080 68_719_476_407,
1081 68_719_476_391,
1082 68_719_476_389,
1083 68_719_476_377,
1084 68_719_476_361,
1085 68_719_476_323,
1086 68_719_476_307,
1087 68_719_476_281,
1088 68_719_476_271,
1089 68_719_476_257,
1090 68_719_476_247,
1091 68_719_476_209,
1092 68_719_476_197,
1093 68_719_476_181,
1094 68_719_476_169,
1095 68_719_476_157,
1096 68_719_476_149,
1097 68_719_476_109,
1098 68_719_476_053,
1099 68_719_476_047,
1100 68_719_476_019,
1101 68_719_475_977,
1102 68_719_475_947,
1103 68_719_475_933,
1104 68_719_475_911,
1105 68_719_475_893,
1106 68_719_475_879,
1107 68_719_475_837,
1108 68_719_475_827,
1109 68_719_475_809,
1110 68_719_475_791,
1111 68_719_475_779,
1112 68_719_475_771,
1113 68_719_475_767,
1114 68_719_475_731,
1115 68_719_475_729,
1116 ];
1117
1118 const PRIMES37: &[u64] = &[
1119 137_438_953_447,
1120 137_438_953_441,
1121 137_438_953_427,
1122 137_438_953_403,
1123 137_438_953_349,
1124 137_438_953_331,
1125 137_438_953_273,
1126 137_438_953_271,
1127 137_438_953_121,
1128 137_438_953_097,
1129 137_438_953_037,
1130 137_438_953_009,
1131 137_438_952_953,
1132 137_438_952_901,
1133 137_438_952_887,
1134 137_438_952_869,
1135 137_438_952_853,
1136 137_438_952_731,
1137 137_438_952_683,
1138 137_438_952_611,
1139 137_438_952_529,
1140 137_438_952_503,
1141 137_438_952_491,
1142 ];
1143
1144 const PRIMES38: &[u64] = &[
1145 274_877_906_899,
1146 274_877_906_857,
1147 274_877_906_837,
1148 274_877_906_813,
1149 274_877_906_791,
1150 274_877_906_759,
1151 274_877_906_753,
1152 274_877_906_717,
1153 274_877_906_713,
1154 274_877_906_687,
1155 274_877_906_647,
1156 274_877_906_629,
1157 274_877_906_627,
1158 274_877_906_573,
1159 274_877_906_543,
1160 274_877_906_491,
1161 274_877_906_477,
1162 274_877_906_473,
1163 274_877_906_431,
1164 274_877_906_419,
1165 274_877_906_341,
1166 274_877_906_333,
1167 274_877_906_327,
1168 274_877_906_321,
1169 274_877_906_309,
1170 274_877_906_267,
1171 274_877_906_243,
1172 274_877_906_213,
1173 274_877_906_209,
1174 274_877_906_203,
1175 274_877_906_179,
1176 274_877_906_167,
1177 274_877_906_119,
1178 274_877_906_063,
1179 274_877_906_053,
1180 274_877_906_021,
1181 274_877_905_931,
1182 ];
1183
1184 const PRIMES39: &[u64] = &[
1185 549_755_813_881,
1186 549_755_813_869,
1187 549_755_813_821,
1188 549_755_813_797,
1189 549_755_813_753,
1190 549_755_813_723,
1191 549_755_813_669,
1192 549_755_813_657,
1193 549_755_813_647,
1194 549_755_813_587,
1195 549_755_813_561,
1196 549_755_813_513,
1197 549_755_813_507,
1198 549_755_813_461,
1199 549_755_813_417,
1200 549_755_813_401,
1201 549_755_813_371,
1202 549_755_813_359,
1203 549_755_813_357,
1204 549_755_813_351,
1205 549_755_813_339,
1206 549_755_813_317,
1207 549_755_813_311,
1208 549_755_813_281,
1209 549_755_813_239,
1210 549_755_813_231,
1211 549_755_813_213,
1212 549_755_813_207,
1213 549_755_813_197,
1214 549_755_813_183,
1215 549_755_813_161,
1216 549_755_813_149,
1217 549_755_813_147,
1218 549_755_813_143,
1219 549_755_813_141,
1220 549_755_813_059,
1221 549_755_813_027,
1222 549_755_813_003,
1223 549_755_812_951,
1224 549_755_812_937,
1225 549_755_812_933,
1226 549_755_812_889,
1227 549_755_812_867,
1228 ];
1229
1230 const PRIMES40: &[u64] = &[
1231 1_099_511_627_689,
1232 1_099_511_627_609,
1233 1_099_511_627_581,
1234 1_099_511_627_573,
1235 1_099_511_627_563,
1236 1_099_511_627_491,
1237 1_099_511_627_483,
1238 1_099_511_627_477,
1239 1_099_511_627_387,
1240 1_099_511_627_339,
1241 1_099_511_627_321,
1242 1_099_511_627_309,
1243 1_099_511_627_297,
1244 1_099_511_627_293,
1245 1_099_511_627_261,
1246 1_099_511_627_213,
1247 1_099_511_627_191,
1248 1_099_511_627_177,
1249 1_099_511_627_173,
1250 1_099_511_627_143,
1251 1_099_511_627_089,
1252 1_099_511_626_987,
1253 1_099_511_626_949,
1254 1_099_511_626_937,
1255 1_099_511_626_793,
1256 1_099_511_626_781,
1257 1_099_511_626_771,
1258 ];
1259
1260 const PRIMES41: &[u64] = &[
1261 2_199_023_255_531,
1262 2_199_023_255_521,
1263 2_199_023_255_497,
1264 2_199_023_255_489,
1265 2_199_023_255_479,
1266 2_199_023_255_477,
1267 2_199_023_255_461,
1268 2_199_023_255_441,
1269 2_199_023_255_419,
1270 2_199_023_255_413,
1271 2_199_023_255_357,
1272 2_199_023_255_327,
1273 2_199_023_255_291,
1274 2_199_023_255_279,
1275 2_199_023_255_267,
1276 2_199_023_255_243,
1277 2_199_023_255_203,
1278 2_199_023_255_171,
1279 2_199_023_255_137,
1280 2_199_023_255_101,
1281 2_199_023_255_087,
1282 2_199_023_255_081,
1283 2_199_023_255_069,
1284 2_199_023_255_027,
1285 2_199_023_255_021,
1286 2_199_023_254_979,
1287 2_199_023_254_933,
1288 2_199_023_254_913,
1289 2_199_023_254_907,
1290 2_199_023_254_903,
1291 2_199_023_254_843,
1292 2_199_023_254_787,
1293 2_199_023_254_699,
1294 2_199_023_254_693,
1295 2_199_023_254_657,
1296 2_199_023_254_567,
1297 ];
1298
1299 const PRIMES42: &[u64] = &[
1300 4_398_046_511_093,
1301 4_398_046_511_087,
1302 4_398_046_511_071,
1303 4_398_046_511_051,
1304 4_398_046_511_039,
1305 4_398_046_510_961,
1306 4_398_046_510_943,
1307 4_398_046_510_939,
1308 4_398_046_510_889,
1309 4_398_046_510_877,
1310 4_398_046_510_829,
1311 4_398_046_510_787,
1312 4_398_046_510_771,
1313 4_398_046_510_751,
1314 4_398_046_510_733,
1315 4_398_046_510_721,
1316 4_398_046_510_643,
1317 4_398_046_510_639,
1318 4_398_046_510_597,
1319 4_398_046_510_577,
1320 4_398_046_510_547,
1321 4_398_046_510_531,
1322 4_398_046_510_463,
1323 4_398_046_510_397,
1324 4_398_046_510_391,
1325 4_398_046_510_379,
1326 4_398_046_510_357,
1327 4_398_046_510_331,
1328 4_398_046_510_327,
1329 4_398_046_510_313,
1330 4_398_046_510_283,
1331 4_398_046_510_279,
1332 4_398_046_510_217,
1333 4_398_046_510_141,
1334 4_398_046_510_133,
1335 4_398_046_510_103,
1336 4_398_046_510_093,
1337 ];
1338
1339 const PRIMES43: &[u64] = &[
1340 8_796_093_022_151,
1341 8_796_093_022_141,
1342 8_796_093_022_091,
1343 8_796_093_022_033,
1344 8_796_093_021_953,
1345 8_796_093_021_941,
1346 8_796_093_021_917,
1347 8_796_093_021_899,
1348 8_796_093_021_889,
1349 8_796_093_021_839,
1350 8_796_093_021_803,
1351 8_796_093_021_791,
1352 8_796_093_021_769,
1353 8_796_093_021_763,
1354 8_796_093_021_743,
1355 8_796_093_021_671,
1356 8_796_093_021_607,
1357 8_796_093_021_587,
1358 8_796_093_021_533,
1359 8_796_093_021_523,
1360 8_796_093_021_517,
1361 8_796_093_021_493,
1362 8_796_093_021_467,
1363 8_796_093_021_461,
1364 8_796_093_021_449,
1365 8_796_093_021_409,
1366 8_796_093_021_407,
1367 8_796_093_021_371,
1368 8_796_093_021_347,
1369 8_796_093_021_337,
1370 8_796_093_021_281,
1371 8_796_093_021_269,
1372 ];
1373
1374 const PRIMES44: &[u64] = &[
1375 17_592_186_044_399,
1376 17_592_186_044_299,
1377 17_592_186_044_297,
1378 17_592_186_044_287,
1379 17_592_186_044_273,
1380 17_592_186_044_267,
1381 17_592_186_044_129,
1382 17_592_186_044_089,
1383 17_592_186_044_057,
1384 17_592_186_044_039,
1385 17_592_186_043_987,
1386 17_592_186_043_921,
1387 17_592_186_043_889,
1388 17_592_186_043_877,
1389 17_592_186_043_841,
1390 17_592_186_043_829,
1391 17_592_186_043_819,
1392 17_592_186_043_813,
1393 17_592_186_043_807,
1394 17_592_186_043_741,
1395 17_592_186_043_693,
1396 17_592_186_043_667,
1397 17_592_186_043_631,
1398 17_592_186_043_591,
1399 17_592_186_043_577,
1400 17_592_186_043_547,
1401 17_592_186_043_483,
1402 17_592_186_043_451,
1403 17_592_186_043_433,
1404 17_592_186_043_409,
1405 ];
1406
1407 const PRIMES45: &[u64] = &[
1408 35_184_372_088_777,
1409 35_184_372_088_763,
1410 35_184_372_088_751,
1411 35_184_372_088_739,
1412 35_184_372_088_711,
1413 35_184_372_088_699,
1414 35_184_372_088_693,
1415 35_184_372_088_673,
1416 35_184_372_088_639,
1417 35_184_372_088_603,
1418 35_184_372_088_571,
1419 35_184_372_088_517,
1420 35_184_372_088_493,
1421 35_184_372_088_471,
1422 35_184_372_088_403,
1423 35_184_372_088_391,
1424 35_184_372_088_379,
1425 35_184_372_088_363,
1426 35_184_372_088_321,
1427 35_184_372_088_319,
1428 35_184_372_088_279,
1429 35_184_372_088_259,
1430 35_184_372_088_249,
1431 35_184_372_088_241,
1432 35_184_372_088_223,
1433 35_184_372_088_183,
1434 35_184_372_088_097,
1435 35_184_372_088_081,
1436 35_184_372_088_079,
1437 35_184_372_088_051,
1438 35_184_372_088_043,
1439 35_184_372_088_039,
1440 35_184_372_087_937,
1441 35_184_372_087_929,
1442 35_184_372_087_923,
1443 35_184_372_087_881,
1444 35_184_372_087_877,
1445 35_184_372_087_869,
1446 ];
1447
1448 const PRIMES46: &[u64] = &[
1449 70_368_744_177_643,
1450 70_368_744_177_607,
1451 70_368_744_177_601,
1452 70_368_744_177_587,
1453 70_368_744_177_497,
1454 70_368_744_177_467,
1455 70_368_744_177_427,
1456 70_368_744_177_377,
1457 70_368_744_177_359,
1458 70_368_744_177_353,
1459 70_368_744_177_331,
1460 70_368_744_177_289,
1461 70_368_744_177_283,
1462 70_368_744_177_271,
1463 70_368_744_177_257,
1464 70_368_744_177_227,
1465 70_368_744_177_167,
1466 70_368_744_177_113,
1467 70_368_744_177_029,
1468 70_368_744_176_959,
1469 70_368_744_176_921,
1470 70_368_744_176_909,
1471 70_368_744_176_879,
1472 70_368_744_176_867,
1473 70_368_744_176_833,
1474 70_368_744_176_827,
1475 70_368_744_176_807,
1476 70_368_744_176_779,
1477 70_368_744_176_777,
1478 70_368_744_176_729,
1479 70_368_744_176_719,
1480 70_368_744_176_711,
1481 ];
1482
1483 const PRIMES47: &[u64] = &[
1484 140_737_488_355_213,
1485 140_737_488_355_201,
1486 140_737_488_355_181,
1487 140_737_488_355_049,
1488 140_737_488_355_031,
1489 140_737_488_354_989,
1490 140_737_488_354_893,
1491 140_737_488_354_787,
1492 140_737_488_354_709,
1493 140_737_488_354_679,
1494 140_737_488_354_613,
1495 140_737_488_354_557,
1496 140_737_488_354_511,
1497 140_737_488_354_431,
1498 140_737_488_354_413,
1499 140_737_488_354_409,
1500 140_737_488_354_373,
1501 140_737_488_354_347,
1502 140_737_488_354_329,
1503 ];
1504
1505 const PRIMES48: &[u64] = &[
1506 281_474_976_710_597,
1507 281_474_976_710_591,
1508 281_474_976_710_567,
1509 281_474_976_710_563,
1510 281_474_976_710_509,
1511 281_474_976_710_491,
1512 281_474_976_710_467,
1513 281_474_976_710_423,
1514 281_474_976_710_413,
1515 281_474_976_710_399,
1516 281_474_976_710_339,
1517 281_474_976_710_327,
1518 281_474_976_710_287,
1519 281_474_976_710_197,
1520 281_474_976_710_143,
1521 281_474_976_710_131,
1522 281_474_976_710_129,
1523 281_474_976_710_107,
1524 281_474_976_710_089,
1525 281_474_976_710_087,
1526 281_474_976_710_029,
1527 281_474_976_709_987,
1528 281_474_976_709_891,
1529 281_474_976_709_859,
1530 281_474_976_709_831,
1531 281_474_976_709_757,
1532 281_474_976_709_741,
1533 281_474_976_709_711,
1534 281_474_976_709_649,
1535 281_474_976_709_637,
1536 ];
1537
1538 const PRIMES49: &[u64] = &[
1539 562_949_953_421_231,
1540 562_949_953_421_201,
1541 562_949_953_421_189,
1542 562_949_953_421_173,
1543 562_949_953_421_131,
1544 562_949_953_421_111,
1545 562_949_953_421_099,
1546 562_949_953_421_047,
1547 562_949_953_421_029,
1548 562_949_953_420_973,
1549 562_949_953_420_871,
1550 562_949_953_420_867,
1551 562_949_953_420_837,
1552 562_949_953_420_793,
1553 562_949_953_420_747,
1554 562_949_953_420_741,
1555 562_949_953_420_733,
1556 562_949_953_420_727,
1557 562_949_953_420_609,
1558 562_949_953_420_571,
1559 562_949_953_420_559,
1560 562_949_953_420_553,
1561 562_949_953_420_523,
1562 562_949_953_420_507,
1563 562_949_953_420_457,
1564 562_949_953_420_403,
1565 562_949_953_420_373,
1566 562_949_953_420_369,
1567 562_949_953_420_343,
1568 562_949_953_420_303,
1569 562_949_953_420_297,
1570 ];
1571
1572 const PRIMES50: &[u64] = &[
1573 1_125_899_906_842_597,
1574 1_125_899_906_842_589,
1575 1_125_899_906_842_573,
1576 1_125_899_906_842_553,
1577 1_125_899_906_842_511,
1578 1_125_899_906_842_507,
1579 1_125_899_906_842_493,
1580 1_125_899_906_842_463,
1581 1_125_899_906_842_429,
1582 1_125_899_906_842_391,
1583 1_125_899_906_842_357,
1584 1_125_899_906_842_283,
1585 1_125_899_906_842_273,
1586 1_125_899_906_842_247,
1587 1_125_899_906_842_201,
1588 1_125_899_906_842_177,
1589 1_125_899_906_842_079,
1590 1_125_899_906_842_033,
1591 1_125_899_906_842_021,
1592 1_125_899_906_842_013,
1593 1_125_899_906_841_973,
1594 1_125_899_906_841_971,
1595 1_125_899_906_841_959,
1596 1_125_899_906_841_949,
1597 1_125_899_906_841_943,
1598 1_125_899_906_841_917,
1599 1_125_899_906_841_901,
1600 1_125_899_906_841_883,
1601 1_125_899_906_841_859,
1602 1_125_899_906_841_811,
1603 1_125_899_906_841_803,
1604 1_125_899_906_841_751,
1605 1_125_899_906_841_713,
1606 1_125_899_906_841_673,
1607 1_125_899_906_841_653,
1608 1_125_899_906_841_623,
1609 1_125_899_906_841_613,
1610 ];
1611
1612 #[test]
1613 fn fails_on_directory() {
1614 new_ucmd!().pipe_in(".").fails();
1615 }
1616
1617 #[test]
1618 fn test_large_number() {
1619 // fixed with num-prime 0.5.0
1620 // https://github.com/uutils/num-prime/issues/23
1621 new_ucmd!()
1622 .arg("4611686018427387896")
1623 .succeeds()
1624 .stdout_is("4611686018427387896: 2 2 2 179951 3203431780337\n");
1625 }
1626
1627 #[test]
1628 fn succeeds_with_numbers_larger_than_u64() {
1629 new_ucmd!()
1630 .arg("158909489063877810457")
1631 .succeeds()
1632 .stdout_is("158909489063877810457: 3401347 3861211 12099721\n");
1633 new_ucmd!()
1634 .arg("222087527029934481871")
1635 .succeeds()
1636 .stdout_is("222087527029934481871: 15601 26449 111427 4830277\n");
1637 new_ucmd!()
1638 .arg("12847291069740315094892340035")
1639 .succeeds()
1640 .stdout_is(
1641 "12847291069740315094892340035: \
1642 5 4073 18899 522591721 63874247821\n",
1643 );
1644 }
1645
1646 #[test]
1647 fn succeeds_with_numbers_larger_than_u128() {
1648 new_ucmd!()
1649 .arg("-h")
1650 .arg("340282366920938463463374607431768211456")
1651 .succeeds()
1652 .stdout_is("340282366920938463463374607431768211456: 2^128\n");
1653 new_ucmd!()
1654 .arg("+170141183460469231731687303715884105729")
1655 .succeeds()
1656 .stdout_is(
1657 "170141183460469231731687303715884105729: \
1658 3 56713727820156410577229101238628035243\n",
1659 );
1660 }
1661
1662 #[test]
1663 fn succeeds_with_numbers_larger_than_u256() {
1664 new_ucmd!()
1665 .arg("-h")
1666 .arg(
1667 "115792089237316195423570985008687907853\
1668 269984665640564039457584007913129639936",
1669 )
1670 .succeeds()
1671 .stdout_is(
1672 "115792089237316195423570985008687907853\
1673 269984665640564039457584007913129639936: 2^256\n",
1674 );
1675 }
1676
1677 #[test]
1678 fn handles_non_unicode_data() {
1679 let input = b"\0 \xFF\0\xFF\xAA\0\xAA\x44 a&#2\n6 9\x003\xC024\t2\t\t4\x000+4\xFF \xF7\xC1";
1680 let expected_out = "6: 2 3\n9: 3 3\n2: 2\n4: 2 2\n";
1681 let expected_err = r"factor: '' is not a valid positive integer
1682 factor: '\377' is not a valid positive integer
1683 factor: 'a&#2' is not a valid positive integer
1684 factor: '\367\301' is not a valid positive integer
1685 ";
1686 new_ucmd!()
1687 .pipe_in(input)
1688 .fails_with_code(1)
1689 .stdout_is(expected_out)
1690 .stderr_is(expected_err);
1691 }
1692
1693 // GNU's `tests/factor/factor.pl` `cont` test passes `factor a 4` and expects
1694 // `factor: 'a' is not a valid positive integer` while still factoring 4.
1695 #[test]
1696 fn invalid_cmdline_arg_continues() {
1697 new_ucmd!()
1698 .args(&["a", "4"])
1699 .fails_with_code(1)
1700 .stdout_is("4: 2 2\n")
1701 .stderr_is("factor: 'a' is not a valid positive integer\n");
1702 }
1703
1704 #[cfg(unix)]
1705 #[test]
1706 fn test_stdin_clean_error_message() {
1707 use std::fs;
1708 use uutests::util::TestScenario;
1709 use uutests::util_name;
1710
1711 let scene = TestScenario::new(util_name!());
1712 let dir = scene.fixtures.plus("directory");
1713 fs::create_dir_all(&dir).unwrap();
1714
1715 let dir_as_file = fs::File::open(&dir).unwrap();
1716
1717 scene
1718 .ucmd()
1719 .set_stdin(dir_as_file)
1720 .fails()
1721 .stderr_is("factor: error reading input: Is a directory\n");
1722 }