We can factorize values to find the values which can multiply together to give the result: [33] [2,542] [743,243] [9,843,254] [653,764,321] Values which have prime number factors: [33,127] [1,017,251,959] Values which are prime numbers: [59,863] [16,993] [22,700,379,89] -->
Integer Factorization in Rust |
Code
An outline of the code is:
extern crate reikna; extern crate thousands; use reikna::factor::quick_factorize; use std::env; use thousands::Separable; fn main() { let mut x=5332; let args: Vec= env::args().collect(); if args.len() >1 { x = args[1].parse().unwrap();} let fac = quick_factorize(x); println!("Input: {}",x.separate_with_commas()); println!("Factors: {:?}",fac); print!("\n {}= ",x); let mut count=1; for f in fac.iter() { count=count+1; if fac.len()==count-1 { print!("{:}",f); } else { print!("{:}x",f.separate_with_commas()); } } }
And a sample run is:
Input: 653,764,321,953,243 Factors: [3, 3, 17, 51151, 83536381] 653764321953243= 3x3x17x51,151x83,536,381