File tree Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -5,29 +5,25 @@ fn main() {
55fn largest_prime_factor ( x : i64 ) -> f64 {
66 let mut largest: f64 = -1.0 ;
77 let mut x_copy: f64 = x. clone ( ) as f64 ;
8- let x_start_value : f64 = x . clone ( ) as f64 ;
8+ let upper_limit : i64 = ( x as f64 ) . sqrt ( ) as i64 ;
99
1010 while x_copy % 2.0 == 0.0 {
1111 largest = 2.0 ;
1212 x_copy /= 2.0 ;
1313 }
14-
1514 while x_copy % 3.0 == 0.0 {
1615 largest = 3.0 ;
1716 x_copy /= 3.0 ;
1817 }
19- let mut i: f64 = 5.0 ;
20- while i <= x_start_value. sqrt ( )
21- {
22- while x_copy % i == 0.0 {
23- largest = i;
24- x_copy = x_copy / i;
18+ for i in ( 5 ..upper_limit) . step_by ( 6 ) {
19+ while x_copy % i as f64 == 0.0 {
20+ largest = i as f64 ;
21+ x_copy = x_copy / i as f64 ;
2522 }
26- while x_copy % ( i + 2.0 ) == 0.0 {
27- largest = i + 2.0 ;
28- x_copy = x_copy / ( i + 2.0 ) ;
23+ while x_copy % ( i + 2 ) as f64 == 0.0 {
24+ largest = ( i + 2 ) as f64 ;
25+ x_copy = x_copy / ( i + 2 ) as f64 ;
2926 }
30- i += 6.0 ;
3127 }
3228 largest
3329}
You can’t perform that action at this time.
0 commit comments